From 076069f7dc1ef8991aa3a575d76bf53f7ccca7da Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 3 Jan 2022 16:31:37 +0000 Subject: [PATCH] only set cache-control: immutable when appropriate --- .changeset/wild-eyes-walk.md | 5 +++++ packages/adapter-node/src/handler.js | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/wild-eyes-walk.md diff --git a/.changeset/wild-eyes-walk.md b/.changeset/wild-eyes-walk.md new file mode 100644 index 000000000000..02da6fd2ddc8 --- /dev/null +++ b/.changeset/wild-eyes-walk.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-node': patch +--- + +Only set cache-control: immutable when appropriate diff --git a/packages/adapter-node/src/handler.js b/packages/adapter-node/src/handler.js index b4a01ab35ee1..3344430adc4c 100644 --- a/packages/adapter-node/src/handler.js +++ b/packages/adapter-node/src/handler.js @@ -18,14 +18,15 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * @param {string} path * @param {number} max_age + * @param {boolean} immutable */ -function serve(path, max_age) { +function serve(path, max_age, immutable = false) { return ( fs.existsSync(path) && sirv(path, { etag: true, maxAge: max_age, - immutable: true, + immutable, gzip: true, brotli: true }) @@ -80,7 +81,7 @@ function sequence(handlers) { export const handler = sequence( [ - serve(path.join(__dirname, '/client'), 31536000), + serve(path.join(__dirname, '/client'), 31536000, true), serve(path.join(__dirname, '/static'), 0), serve(path.join(__dirname, '/prerendered'), 0), ssr