forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use manual surrogate key for nextjs static assets (github#25096)
* use manual surrogate key for nextjs static assets * refactor
- Loading branch information
Showing
3 changed files
with
26 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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]{20}/.test(path)) return true | ||
return false | ||
} |