Skip to content

perf: cache the versioned assets for a year - #11

Merged
simien merged 1 commit into
mainfrom
chore/asset-cache-headers
Sep 13, 2026
Merged

simien merged 1 commit into
mainfrom
chore/asset-cache-headers

Conversation

@simien

@simien simien commented Sep 13, 2026

Copy link
Copy Markdown
Owner

What does this change?

Adds Cache-Control: public, max-age=31536000, immutable in _headers for the six files that are requested with a ?v= query: style.css, generator.js, guide.css, and the three screenshot files.

Today every asset carries Cloudflare's default max-age=0, must-revalidate, so a returning visitor revalidates the stylesheet and the generator on every load. That's two round trips before first paint that the ?v= scheme already makes unnecessary: the number moves whenever the file changes, and CI fails the build when it doesn't (both directions, on every page that requests the file).

Left on the default on purpose:

  • The HTML pages, whose names never change and must be checked each visit.
  • vendor/gif/*, which carries no ?v=. A swapped file under the same name would sit stale for a year.

Related issue

None. Noticed while looking at the LCP report.

How was this tested?

  • curl -I against this branch's Workers preview, before merge, to confirm the versioned assets carry the new header and the pages do not (result in the PR comments below once the preview is up).
  • python3 .github/scripts/checks.py main passes.

Checklist

  • No new build step, package manager, framework, or CDN dependency introduced
  • generator.js still has no dependency on the UI, if touched (not touched)
  • Tested locally in at least one browser (not applicable; the change is a Cloudflare response header, verified on the preview deployment)

🤖 Generated with Claude Code

Every asset carried Cloudflare's default of max-age=0, must-revalidate,
so a returning visitor revalidated style.css and generator.js on every
load, two round trips before first paint that the ?v= scheme already
makes unnecessary: the number moves whenever the file does, and CI fails
the build when it does not. The six files that carry a ?v= now get a
year-long immutable cache. Pages keep the default, since their names
never change, and so does the vendored GIF encoder, which has no ?v=.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
flield ef8cc4b Commit Preview URL

Branch Preview URL
Sep 13 2026, 10:37 PM

@simien

simien commented Sep 13, 2026

Copy link
Copy Markdown
Owner Author

Verified on this branch's Workers preview with curl -I:

Path cache-control
/style.css?v=105 public, max-age=31536000, immutable
/generator.js?v=12 public, max-age=31536000, immutable
/guide.css?v=4 public, max-age=31536000, immutable
/screenshot-800.webp?v=8 public, max-age=31536000, immutable
/ public, max-age=0, must-revalidate (unchanged)
/guide/ public, max-age=0, must-revalidate (unchanged)
/vendor/gif/gif.js public, max-age=0, must-revalidate (unchanged)

@simien
simien merged commit c77e105 into main Sep 13, 2026
2 checks passed
@simien
simien deleted the chore/asset-cache-headers branch September 13, 2026 22:39
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