This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Feature request: custom cache-control headers #567
Closed
Description
I think I mentioned this in a previous issue, but it would be nice to be able to override Sapper's built-in cache-control headers. Sometimes you want to add public
, or sometimes you want to increase or decrease the max-age
, etc.
Currently I can work around this, but it's extremely hacky:
function overrideSetHeader (req, res, next) {
const origSetHeader = res.setHeader
res.setHeader = function (key, value) {
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=3600'])
}
}
return origSetHeader.apply(this, arguments)
}
return next()
}
app.use(overrideSetHeader, sapper.middleware())
If there's some Express/Polka-standard way for middleware to do this then I'd be happy with that; else maybe it could just be an option passed in to sapper.middleware()
?