Repository navigation
perf(deps): let the browser cache component scripts and stylesheets - #574
Merged
Merged
Conversation
A URL whose hash is a hash of the bytes it serves (a class version's script or stylesheet, a served Dependencies file) now answers with Cache-Control: public, max-age=31536000, immutable, the policy the Events definition and stylesheet routes already use. citry.js, cache/<class_id>.<js|css>, and the css_data() variables stylesheet can change at the same URL, so they answer with Cache-Control: no-cache and an ETag, and return 304 with no body for a current copy. A 404 from these routes says no-store, since another worker may store the file a moment later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/asset-cache-control
branch
from
November 1, 2026 18:52
ced09a6 to
efc8cfc
Compare
citry.js serves the same bytes as ext/events/runtime.js at an unversioned URL. A copy reused on back/forward navigation could pair a page with another runtime and fail its integrity check, so it keeps no-store until the runtimes move to content-hashed URLs (#578). Component URLs keep no-cache with an ETag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/asset-cache-control
branch
from
November 1, 2026 18:55
efc8cfc to
52c84e3
Compare
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.
What changes
The Dependencies routes, including
/citry/citry.js, answered with noCache-Control, so whether the browser kept a copy was left to its own guesses. Each route now says what the browser may do:Cache-Controlcache/<class_id>.<hash>.<js|css>(a class version)public, max-age=31536000, immutableasset/<hash>.<ext>public, max-age=31536000, immutablecache/<class_id>.<js|css>no-cache+ETag,304for a current copycitry.jsno-storecache/<class_id>.<vars_hash>.css(css_data()stylesheet)no-cache+ETag404from these routesno-storeThe immutable value is the one the Events definition and stylesheet routes already sent. It is now one constant (
IMMUTABLE_CACHE_CONTROL) that both extensions use. The WSGI adapter gains a304 Not Modifiedstatus line.citry.jsand the Events and i18n runtimes (ext/events/runtime.js,ext/i18n/runtime.js) all useno-storein 0.7.0. Withno-cache, a back or forward navigation may reuse a stored runtime without asking, so right after a deploy a page could pair new HTML with the old runtime and, withsecurity_script_integrityon, fail its integrity check. The v1.1 follow-up serves the runtimes from content-hashed URLs instead (#578).Component URLs without a content hash keep
no-cache+ETag. Script integrity applies to scripts only. Citry's pages link component JavaScript by its content-hashed URL, so the unhashedcache/<class_id>.jsis not what an integrity-checked page loads. Thecss_data()stylesheet is CSS, so integrity does not apply to it. A stale copy after an upgrade that changes the stylesheet format would only look wrong until a reload.Tests
packages/py/citry/tests/test_asset_cors.py:If-None-Matchgets304with the caching and CORS headers.*match. Other tags do not.css_data()stylesheet and an unhashed.cssare revalidated.404path sendsno-store.Citryinstances give a component script the same tag.main, the new tests fail.Review
An independent review ran, with a security pass and a prose pass. Its findings are folded in: the variables stylesheet moved off
immutable, the 404s gotno-store, the tag is computed once per content, and the docs and changelog wording was corrected. Security verdict:If-None-Matchis only compared, never echoed back, and the 304s keep CORS andnosniff. No route can be poisoned per user, because each one answersGETwithout reading request data.Known and left as it is: Django's
CommonMiddlewareaddsContent-Length: 0to the 304. Django's own conditional-GET responses do the same, and browsers ignore it.🤖 Generated with Claude Code