1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/middleware/static-asset-caching.js
Peter Bengtsson c1f0030e3a NextJS 12.1.6 (#26102)
* nextjs 12.1.0

* no idea what's going on

* desperate attempts

* wip

* lots of data is necessary for 'npm run build' now

* tidying up

* update package lock
2022-06-28 12:57:38 +00:00

17 lines
582 B
JavaScript

import { setFastlySurrogateKey, SURROGATE_ENUMS } from './set-fastly-surrogate-key.js'
export default function setStaticAssetCaching(req, res, next) {
if (isChecksummed(req.path)) {
setFastlySurrogateKey(res, SURROGATE_ENUMS.MANUAL)
}
return next()
}
// True if the URL is known to contain some pattern of a checksum that
// would make it intelligently different if its content has changed.
function isChecksummed(path) {
if (path.startsWith('/assets/cb-')) return true
if (path.startsWith('/_next/static') && /[a-f0-9]{16}/.test(path)) return true
return false
}