Dani 5,664 The Queen of DaniWeb Administrator Featured Poster

According to this page, Google requires "as a rule of thumb" that the SXG expiration date is less than 1 day in the future if the content is JS, or otherwise 7 days in the future.

My external Javascript files are immutable. Why should they have a 1 day cache life? Currently I am doing something similar to max-age=3600, s-maxage=604800 for HTML files, and a flat max-age=2592000 for JS.

Is this not ideal?

Dani AI

Generated

— Short answer: if a JS file is truly immutable (content-hashed filename, never overwritten at the same URL) it is fine to treat it as a long-lived asset. The extra constraint with signed exchanges is that the signed SXG bundle itself asserts a specific response for a bounded time, so the SXG expiry should reflect the asset's lifecycle. The practical, low-risk approach is to fingerprint JS, give the browser a long Cache-Control with immutable, and ensure SXG signatures are only relied on for the same stable lifecycle — when the file changes, publish a new fingerprint and re-sign the exchange.

Practical checklist and workflow:

  • Produce content-hashed filenames during your build so URLs change on update.
  • Emit browser headers like Cache-Control: public, max-age=<long>, immutable for those fingerprinted files.
  • For CDNs, use s-maxage or CDN-specific TTLs and plan automated purges on deploy for non-fingerprinted assets.
  • When creating SXGs, set the SXG expiry to match the expected lifetime of that fingerprinted asset; re-sign when assets change.
  • Validate and test: check HTTP headers with curl -I or DevTools, use SXG validators and Chrome to confirm the signed bundle and expiry, and monitor Search Console if you rely on platform caches.

References for details on HTTP caching directives and SXG mechanics: MDN on Cache-Control (developer.mozilla.org) and the WICG webpackage docs on signed exchanges (wicg.github.io).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.