fix(webapp): serve the service worker script with no-cache - #6401
Open
rebelchris wants to merge 1 commit into
Open
fix(webapp): serve the service worker script with no-cache#6401rebelchris wants to merge 1 commit into
rebelchris wants to merge 1 commit into
Conversation
/serwist/sw.js was served with a multi-hour browser TTL, so logged-in clients (the only ones with the SW registered) kept running the previous build's precache long after a deploy — fixes looked shipped but production stayed broken for them until the TTL lapsed. Browsers only pick up a new deployment once they re-fetch the SW script, and that fetch honors HTTP caching. Override Cache-Control at the route handler (stored in the prerender) and mirror it in next.config headers so update checks revalidate every time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
The problem
After #6400 deployed, production still showed the broken wide cards for logged-in users — while every logged-out check (and the preview deployment) looked fixed.
Cause: the webapp registers its Serwist service worker only for logged-in users (
register={!!user}in_app.tsx), and the SW precaches the app shell. Clients only pick up a new deployment when they re-fetch/serwist/sw.js(it hasskipWaiting: true, so a fresh script activates immediately) — but that fetch honors HTTP caching, and production served the script withcache-control: public, max-age=14400. Net effect: every deploy takes up to 4+ hours to reach logged-in users, our whole active audience.The route (
app/serwist/[path]/route.ts, aforce-statichandler from@serwist/turbopack) setsContent-TypeandService-Worker-Allowedbut noCache-Control, so it fell through to default static caching.The fix
Serve the SW script with
Cache-Control: no-cache, must-revalidateso every SW update check revalidates (ETag makes the common case a cheap 304):GETto set the header — it's stored in the prerender (sw.js.metanow recordscache-control: no-cache, must-revalidate).next.config.tsheaders()for/serwist/:path*as a routing-layer backstop.Testing
pnpm --filter webapp buildpasses; the prerendered/serwist/sw.jsresponse metadata contains the new header.curl -sI https://<preview>/serwist/sw.js | grep -i cache-controlshould showno-cache, must-revalidate.Note: if Cloudflare in front of production has a "Browser Cache TTL" override or cache rule matching
*.js, it may still rewrite this header — worth checking the zone config after merge.🤖 Generated with Claude Code
Preview domain
https://fix-sw-no-cache.preview.app.daily.dev