-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add full page caching #13
base: main
Are you sure you want to change the base?
feat: add full page caching #13
Conversation
dc85a50
to
5e75ac2
Compare
✅ Deploy Preview for hydrogen-remix-template ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
b05ebd3
to
3489a29
Compare
app/lib/page-cache.ts
Outdated
export const NO_CACHE = { | ||
'Cache-Control': 'private, no-store, no-cache, must-revalidate', | ||
}; | ||
|
||
export const CACHE_1_DAY = { | ||
'Cache-Control': 'public, max-age=0', | ||
}; | ||
|
||
export const CACHE_1_HOUR_SWR = { | ||
'Cache-Control': 'public, max-age=0, must-revalidate', | ||
'Netlify-CDN-Cache-Control': | ||
'public, max-age=3600, stale-while-revalidate=60', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be a good use case for Matt's https:/ascorbic/cdn-cache-control/
app/routes/_index.tsx
Outdated
|
||
export const meta: MetaFunction = () => { | ||
return [{title: 'Hydrogen | Home'}]; | ||
}; | ||
|
||
export const headers: HeadersFunction = () => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://remix.run/docs/en/main/route/headers
This is inherited by all child routes, unless a child route (or... closer ancestor parent route) overrides it.
779d700
to
30736b2
Compare
30736b2
to
5632931
Compare
Cache most pages for 1 hour on the Netlify CDN with stale-while-revalidate (allowing 1 min for background revalidation to complete). Cache these also on browsers (and anything else upstream) but require a conditional request to revalidate. On the search page, vary on the search input. Disable this caching on pages that have personalization: account/*, cart.
5632931
to
266f746
Compare
Description
This may be more digestible if you review commit by commit, as it's really three separate changes that come together. See also #14 as a follow-up.
Make pages cacheable
This PR makes all pages load the cart and customer account data client side only. This results in all SSR page responses (except the
/account/*
pages) cacheable on a public CDN like Netlify's.See https://shopify.dev/docs/storefronts/headless/hydrogen/cart/render-client-side for the approach (but note that there are a few errors on that page, for which I've submitted feedback).
See also https://shopify.dev/docs/storefronts/headless/hydrogen/caching/full-page-cache for more general information on full-page caching with Hydrogen.
Cache the pages
Cache most pages for 1 hour on the Netlify CDN with stale-while-revalidate (allowing 1 min for background revalidation to complete). Cache these also on browsers (and anything else upstream) but require a conditional request to revalidate.
On the search page, vary on the search input.
Disable this caching on pages that have un-deferred personalization, which is the
/account/*
pages. (Technically we could apply the same pattern here, but the trade-off calculation is pretty different.)Make data routes cacheable
This also caches resource routes by default, with once again the account and cart opted out. This makes client-side navigation leverage caching as well.