Update cache headers to include max-age and immutable#12420
Merged
sfc-gh-gwatters merged 3 commits intodevelopfrom Sep 4, 2025
Merged
Update cache headers to include max-age and immutable#12420sfc-gh-gwatters merged 3 commits intodevelopfrom
max-age and immutable#12420sfc-gh-gwatters merged 3 commits intodevelopfrom
Conversation
Contributor
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
Contributor
✅ PR preview is ready!
|
vdonato
approved these changes
Sep 3, 2025
a9eaebb to
a2d95df
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates cache headers for static assets to include explicit max-age and immutable directives instead of relying on browser heuristic caching. The change addresses the issue where browsers use unpredictable heuristic caching (typically 10% of time since Last-Modified) for assets without explicit cache duration, which can result in very short cache times for recently deployed files.
- Updates cache control headers to use explicit one-year max-age for hashed static assets
- Adds
immutabledirective to indicate cached assets won't change - Maintains no-cache behavior for HTML files and manifest.json files
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/streamlit/web/server/routes.py | Updates StaticFileHandler to set explicit cache headers with max-age and immutable for hashed assets |
| lib/tests/streamlit/web/server/routes_test.py | Adds comprehensive test coverage for the new cache control header behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Without
max-agedefined in the cache header, browsers fallback to use a heuristic caching strategy which is typically (Chrome)10% of the time since the "Last Modified" header (see https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.2). Firefox caps this at a week. Since the files being served all contain a hash, the actual cache duration can be much much longer.For environments where the static files get written at deployment or startup time, the heuristic cache can be on the order of minutes/hours.
GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.