Last active
July 1, 2024 14:33
-
-
Save Danetag/7adea1b3ea671d62e38c84065d1ac02e to your computer and use it in GitHub Desktop.
Enabling full-page caching on Shopify Hydrogen apps
This file contains hidden or 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
// Check out https://shopify.dev/docs/storefronts/headless/hydrogen/caching/full-page-cache for more information | |
import {CacheCustom, generateCacheControlHeader} from '@shopify/hydrogen'; | |
const fullPageCache = CacheCustom({ | |
mode: 'public', | |
maxAge: 60, | |
staleWhileRevalidate: 86400, | |
}); | |
export default async function handleRequest( | |
request: Request, | |
responseStatusCode: number, | |
responseHeaders: Headers, | |
remixContext: EntryContext, | |
context: AppLoadContext, | |
) { | |
// ... | |
if (responseStatusCode === 200) { | |
// Turn on full page caching | |
responseHeaders.set( | |
'Oxygen-Cache-Control', | |
generateCacheControlHeader(fullPageCache), | |
); | |
responseHeaders.set('Vary', 'Accept-Encoding'); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment