Skip to content

Commit

Permalink
fix: set revalidate cache header on 404'd static assets
Browse files Browse the repository at this point in the history
Some adapters (like Vercel) apply a immutable cache header by default to static assets. They respect explicitly set headers though. Therefore apply a "must immediately revalidate" cache header to the 404 response of static assets in the SvelteKit runtime

related to #9089
  • Loading branch information
dummdidumm committed Aug 1, 2024
1 parent 998edb2 commit 0a6d436
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-pears-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: set revalidate cache header on 404'd static assets
3 changes: 3 additions & 0 deletions packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export async function respond(request, options, manifest, state) {
}

if (decoded.startsWith(`/${options.app_dir}`)) {
// Ensure that 404'd static assets are not cached - some adapters might apply caching by default
const headers = new Headers();
headers.set('cache-control', 'public, max-age=0, must-revalidate');
return text('Not found', { status: 404 });
}

Expand Down

0 comments on commit 0a6d436

Please sign in to comment.