Skip to content

Serve static assets from Firebase Hosting's CDN instead of proxying through Cloud Run - #187

Closed
brianglass wants to merge 1 commit into
mainfrom
firebase-static-hosting
Closed

Serve static assets from Firebase Hosting's CDN instead of proxying through Cloud Run#187
brianglass wants to merge 1 commit into
mainfrom
firebase-static-hosting

Conversation

@brianglass

Copy link
Copy Markdown
Owner

Summary

  • make firebase now runs collectstatic first and mirrors the output into public/media (matching STATIC_URL='media/'), so Firebase Hosting serves these files directly from its own CDN on the next deploy instead of proxying every static-asset request through Cloud Run.
  • No firebase.json changes needed -- Firebase Hosting only falls back to the catch-all Cloud Run rewrite when no literal file matches under public/, so a matching file there is served directly. Confirmed this empirically via the Firebase Hosting emulator (see test plan).
  • public/media is gitignored (build output, regenerated by the Makefile target) and servestatic's own compressed sidecar files (.br/.gz/.zstd) are stripped from the copy, since Firebase compresses on the fly at its CDN edge and never looks for them.
  • servestatic itself stays in the app -- it's still needed for local dev (no Firebase Hosting in front of docker compose) and the orthocal-dev Cloud Run service (not covered by firebase.json's rewrite, which is hardcoded to the orthocal service), plus it's a reasonable fallback if a make firebase deploy is ever forgotten.

Test plan

  • make collectstatic runs cleanly and produces 79 files in public/media, with zero leftover .br/.gz/.zstd sidecar files.
  • Firebase Hosting emulator (firebase emulators:start --only hosting) serves main.css and htmx.min.js from public/media with status 200 and content byte-identical to the source files, with no firebase.json changes.
  • Run make firebase for a real deploy (manual, left to Brian).

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

https://claude.ai/code/session_01Hf6j2xXQXywHVh3HAVRxB3

…hrough Cloud Run

The last real Firebase Hosting deploy of public/ content was ~3.5 years
ago -- since then, everything (including static assets) has gone through
firebase.json's catch-all rewrite to Cloud Run. Since Firebase Hosting
only falls back to that rewrite when no literal file matches under
public/, populating public/media with Django's collectstatic output
(matching STATIC_URL='media/') makes Firebase serve these files directly
from its own CDN on the next `make firebase` deploy, cutting Cloud Run
compute for that traffic without any firebase.json changes.

Verified via the Firebase Hosting emulator: main.css and htmx.min.js
serve with status 200 and byte-identical content from public/media, with
no changes to firebase.json's rewrite rule.

Excludes servestatic's own compressed sidecar files (.br/.gz/.zstd) from
the copy -- those exist for servestatic's on-disk serving scheme, and
Firebase Hosting compresses on the fly at its own CDN edge instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hf6j2xXQXywHVh3HAVRxB3
@brianglass

Copy link
Copy Markdown
Owner Author

Superseded by #191 -- Firebase deploy is now automated via the main Cloud Build trigger (#189), so the manual make firebase workflow this PR was built to support no longer applies. Deleting the Makefile in #191 rather than merging this.

@brianglass brianglass closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant