Skip to content

Instantly share code, notes, and snippets.

@ditman
Last active November 8, 2024 22:28
Show Gist options
  • Save ditman/cb6d1d78be6dc55bb5a0290d08649c8b to your computer and use it in GitHub Desktop.
Save ditman/cb6d1d78be6dc55bb5a0290d08649c8b to your computer and use it in GitHub Desktop.
Sample Firebase hosting configuration for Flutter web.
{
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"headers": [
{
"source": "**/*",
"headers": [
{
"key": "Cross-Origin-Embedder-Policy",
"value": "credentialless"
},
{
"key": "Cross-Origin-Opener-Policy",
"value": "same-origin"
},
{
"key": "Cache-Control",
"value": "no-cache, no-store, must-revalidate"
}
]
},
{
"source":
"**/*.@(jpg|jpeg|gif|png|svg|webp|css|eot|otf|ttf|ttc|woff|woff2|font.css)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=3600,s-maxage=604800"
}
]
},
{
"source":
"**/*.@(mjs|js|wasm|json)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=0,s-maxage=604800"
}
]
}
]
}
}
@ditman
Copy link
Author

ditman commented Nov 8, 2024

Cache

  • Normal assets are configured to be cached for 1h + 7 days across the CDN (the latter is invalidated by firebase hosting when doing a refresh)
  • Application code (js/mjs/wasm/json) is set to expire immediately, to leverage Etag revalidation. This can be raised to something less aggressive, like 5 minutes (300) or a good tradeoff for your deployment cadence.
  • Everything else (html files, other extension types) are set to not be cached at all.

In all cases, exceptions for specific files can be made, like the (non-existent in Flutter web font.css file).

Wasm

This gist also adds COEP/COOP (Cross-Origin-Embedder-Policy and Cross-Origin-Opener-Policy so shared array buffers become available, and Wasm can work in multi-threaded mode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment