From 425d4c74aa4a8753e5e09a6926cb8833761c2eed Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Thu, 14 Feb 2019 22:54:18 -0800 Subject: [PATCH] fix: use "public" for cache-control (#993) another attempt to address #985 --- src/server.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/server.js b/src/server.js index 6a521297..66517d21 100644 --- a/src/server.js +++ b/src/server.js @@ -59,13 +59,19 @@ app.use(serveStatic('static', { app.use(express.static('__sapper__/build/client/report.html')) app.use(express.static('__sapper__/build/client/stats.json')) -// TODO: hack to override Sapper's default max-age of 600 for HTML files +// TODO: hack to override Sapper's default cache-control function overrideSetHeader (req, res, next) { const origSetHeader = res.setHeader res.setHeader = function (key, value) { - if (key === 'Cache-Control' && value === 'max-age=600') { - return origSetHeader.apply(this, ['Cache-Control', `max-age=${MAX_AGE}`]) + if (key === 'Cache-Control') { + if (value === 'max-age=31536000, immutable') { // webpack assets + return origSetHeader.apply(this, ['Cache-Control', 'public,max-age=31536000,immutable']) + } + if (value === 'max-age=600') { // HTML files + return origSetHeader.apply(this, ['Cache-Control', `public,max-age=${MAX_AGE}`]) + } } + return origSetHeader.apply(this, arguments) } return next()