Skip to content

Commit

Permalink
fix(netlify): only cache GET/HEAD methods (#127)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
Skn0tt and sarah11918 authored Jan 11, 2024
1 parent 09306d5 commit 36434f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dry-rules-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

Updates the behavior of the `cacheOnDemandPages` setting to only cache GET/HEAD requests by default
4 changes: 3 additions & 1 deletion packages/netlify/src/ssr-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ export const createExports = (manifest: SSRManifest, _args: Args) => {
}

if (integrationConfig.cacheOnDemandPages) {
const isCacheableMethod = ['GET', 'HEAD'].includes(request.method);

// any user-provided Cache-Control headers take precedence
const hasCacheControl = [
'Cache-Control',
'CDN-Cache-Control',
'Netlify-CDN-Cache-Control',
].some((header) => response.headers.has(header));

if (!hasCacheControl) {
if (isCacheableMethod && !hasCacheControl) {
// caches this page for up to a year
response.headers.append('CDN-Cache-Control', 'public, max-age=31536000, must-revalidate');
}
Expand Down

0 comments on commit 36434f0

Please sign in to comment.