docs: update Firebase Hosting caching examples - #13909
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Firebase Hosting configuration and the web FAQ documentation to optimize caching headers for Flutter web applications, particularly for hashed assets and 404 pages. Feedback on these changes highlights a potential cache poisoning issue where the rewrite exclusion pattern fails to match root files like main.dart.*.js due to a trailing wildcard. Additionally, the 404.html source patterns in both the configuration and documentation are missing a leading slash, which could prevent the cache-control headers from being applied correctly.
|
Staged preview of the updated flutter.dev site (updated for commit f91d4a3): https://flutter-dev-230821--www-pr13909-audit-firebase-docs-u5mlpicq.web.app |
|
Staged preview of the updated docs.flutter.dev site (updated for commit f91d4a3): https://flutter-docs-prod--docs-pr13909-audit-firebase-docs-cktehg15.web.app |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the Firebase Hosting configuration in firebase.json and the web FAQ documentation to optimize caching behavior, prevent caching of 404 responses, and clarify service worker behavior. Feedback on these changes suggests using a leading slash for the 404.html source pattern in firebase.json for consistency, and refining the cache-control configuration in the FAQ documentation to target only entry points and compiled code instead of all assets (**) to avoid performance degradation.
There was a problem hiding this comment.
Code Review
This pull request updates the Firebase Hosting configuration and documentation to ensure proper caching behavior and prevent the caching of missing assets. Specifically, it sets Cache-Control to max-age=0, must-revalidate for all files and the 404.html page, and adds rewrite exclusions for SPA routing. The review feedback suggests using a leading slash for the 404.html source pattern (i.e., /404.html) in both configuration files and the documentation to precisely target the root 404 page. Additionally, for the documentation example, it is recommended to exclude critical root files like flutter_bootstrap.js, flutter.js, and manifest.json from the SPA rewrite rule to avoid syntax errors when these files are missing.
…t cached 404s (#7527) This PR updates `firebase.json` caching rules to match `docs.flutter.dev` ([flutter/website#13909](flutter/website#13909)): 1. **Prevents 7-day/8-hour cached 404s**: Adds `"source": "404.html"` with `Cache-Control: max-age=0, must-revalidate` (which Firebase Hosting evaluates first on all 404 responses before path-matching globs) so missing `/assets/img/*.png` or `.js`/`.css` requests are not cached as 404s for 7 days or 8 hours. 2. **Aligns `.js`/`.css` cache TTL with HTML and Wasm (`max-age=3600`)**: Changes `**/*.@(avif|...|css|js)` from `max-age=28800` (8 hours) to `max-age=3600` (1 hour), matching `docs.flutter.dev` (`sites/docs/firebase.json`) as well as `dart.dev`'s HTML (`max-age=3600`), `main.client.mjs` (`max-age=3600`), and `main.client.wasm` (`max-age=3600`) while preserving 1-hour browser memory-cache hits during multi-page reading sessions. For context and related documentation, see the sibling landed PRs: - flutter/website#13909 - dart-lang/dart-pad#3913
Updates the Firebase Hosting caching guidance in the Web FAQ (
sites/docs/src/content/platform-integration/web/faq.md) and adds a404.htmlnegative-cache rule to bothsites/docs/firebase.json(docs.flutter.dev) andsites/www/firebase.json(flutter.dev):s-maxageon static files: On Firebase Hosting, static files are cached at the CDN edge via internal surrogate controls purged on deploy;Cache-Controlgoverns the browser cache only."source": "**"): Usemax-age=0, must-revalidateinstead of extension-only rules that previously leftindex.htmlat the defaultmax-age=3600(causing up to 1-hour stale shells after deploy)."source": "404.html"): Add explicitmax-age=0, must-revalidaterules to the FAQ example,sites/docs/firebase.json(docs.flutter.dev), andsites/www/firebase.json(flutter.dev) so missing assets (such as/assets/*.png) do not inherit wildcard TTLs (max-age=604800/max-age=3600) at the CDN edge."!(/assets/**|/canvaskit/**|/icons/**|/main.dart.*)"): Exclude asset directories and root compiled entry points (main.dart.wasm,main.dart.mjs,main.dart.js) from/index.htmlcatch-all rewrites so missing assets and bundles return a real404status rather than200 OKHTML.