Skip to content

docs: update Firebase Hosting caching examples - #13909

Merged
kevmoo merged 6 commits into
mainfrom
audit-firebase-docs
Sep 21, 2026
Merged

kevmoo merged 6 commits into
mainfrom
audit-firebase-docs

Conversation

@kevmoo

@kevmoo kevmoo commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Updates the Firebase Hosting caching guidance in the Web FAQ (sites/docs/src/content/platform-integration/web/faq.md) and adds a 404.html negative-cache rule to both sites/docs/firebase.json (docs.flutter.dev) and sites/www/firebase.json (flutter.dev):

  • Drop no-op s-maxage on static files: On Firebase Hosting, static files are cached at the CDN edge via internal surrogate controls purged on deploy; Cache-Control governs the browser cache only.
  • Revalidate all entry points and manifests ("source": "**"): Use max-age=0, must-revalidate instead of extension-only rules that previously left index.html at the default max-age=3600 (causing up to 1-hour stale shells after deploy).
  • Prevent cached 404s ("source": "404.html"): Add explicit max-age=0, must-revalidate rules to the FAQ example, sites/docs/firebase.json (docs.flutter.dev), and sites/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.
  • Guard SPA rewrites ("!(/assets/**|/canvaskit/**|/icons/**|/main.dart.*)"): Exclude asset directories and root compiled entry points (main.dart.wasm, main.dart.mjs, main.dart.js) from /index.html catch-all rewrites so missing assets and bundles return a real 404 status rather than 200 OK HTML.
  • Clarify service worker behavior: Note that newer Flutter releases emit a self-cleaning stub to remove legacy service workers rather than a caching service worker.

@kevmoo
kevmoo requested review from a team and sfshaza2 as code owners September 21, 2026 04:38

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sites/docs/src/content/platform-integration/web/faq.md
Comment thread sites/docs/firebase.json
Comment thread sites/docs/src/content/platform-integration/web/faq.md
@flutter-website-bot

flutter-website-bot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit f91d4a3):

https://flutter-dev-230821--www-pr13909-audit-firebase-docs-u5mlpicq.web.app

@flutter-website-bot

flutter-website-bot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

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

@kevmoo

kevmoo commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sites/docs/firebase.json
Comment thread sites/docs/src/content/platform-integration/web/faq.md
@kevmoo
kevmoo marked this pull request as draft September 21, 2026 06:55
@kevmoo
kevmoo marked this pull request as ready for review September 21, 2026 17:38

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sites/docs/firebase.json
Comment thread sites/www/firebase.json
Comment thread sites/docs/src/content/platform-integration/web/faq.md

@sfshaza2 sfshaza2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. @kevmoo, I leave it to you to decide how to handle the bot's comments. But I'm approving, just to expedite...

@kevmoo kevmoo added the st.RFM Ready to merge or land label Sep 21, 2026
@kevmoo
kevmoo merged commit 7d8f18d into main Sep 21, 2026
16 checks passed
@kevmoo
kevmoo deleted the audit-firebase-docs branch September 21, 2026 21:13
parlough pushed a commit to dart-lang/site-www that referenced this pull request Sep 22, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

st.RFM Ready to merge or land

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants