Static assets: 233 KB re-downloaded on every load becomes 72 KB, or zero #1220
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!1220
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "perf/static-asset-caching"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Static assets: 233 KB re-downloaded on every load becomes 72 KB, or zero
The catalogue was the visible cost; the app itself was the constant one. Five files -
app.jsat129 KB,
canvas.js36 KB,faceplate.js27 KB,style.css30 KB,index.html7 KB - went out withCache-Control: no-storeand no compression, so every load re-downloaded all of it and thebrowser was not even allowed to ask whether anything had changed.
Measured against a running server, all five files:
304sThe bug that made it look like it worked
The first version computed the ETag as
e4 && st.mtimeMs ? st.mtimeMs : Date.now(). The firstargument of an
fs.statcallback is the error, so that expression was always falsy: everyresponse stamped a fresh ETag from the clock, and revalidation could never match. The header was
present, well-formed, and completely useless — and a browser test would have looked fine, because
each response was individually correct.
Caught by measuring bytes instead of reading headers: two consecutive requests for
app.jshadETags ten milliseconds apart (
W/"128993-1794237477972"thenW/"128993-1794237477982").The test now asserts the boring thing directly: two requests for an unchanged file agree on the
ETag, which is what makes a 304 possible at all.
What changed
If-None-MatchandIf-Modified-Sinceboth honoured.Cache-Control: no-cacheinstead ofno-store— still never trusted without asking, butallowed to answer 304. The server doubles as the thing being edited, and a browser holding a stale
app.jsafter a fix is the most confusing bug report there is.(file, mtime, size) so a 129 KB
app.jsis compressed once per version rather than once perrequest.
Content-Lengthset correctly for both encodings, andVary: Accept-Encoding.20 checks in
test/server-static-cache.test.jsagainst a real spawned server: ETag stability, bothvalidators, byte-identical gunzip, Content-Length on both encodings, content types for all five
assets, the SPA fallback, and path traversal still refused. Suite: 126 suites, 5,616 assertions, 0
failed.