Caching localized pages (when URL doesn’t contain language) #69892
Replies: 1 comment
-
The Next.js documented way is to use middleware to detect Once you used dynamic functions like
Maybe you could try the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Maybe I’m approaching this entirely wrong, so feel free to suggest better approaches (I would prefer not to put the language in the URL or domain or path for pages that are not primarily content though)
I use Fastly as a CDN, and would like to be able to cache entire localized pages in it, but my root layout accesses the
Accept-Languageheader to determine which language to render. That triggers dynamic rendering and theCache-Control: … no-cache …headers, as it should.However, in a previous stack I had Fastly resolve the Accept-Language header into a custom
X-Languageheader with the exact language to render, then included that in my cache key to ensure it cached and correctly served each localized page.I’d like to do the same with Next.js App Router, but if I access the
X-Languageit will trigger dynamic rendering andno-cacheetc.Maybe ideally there would be a way to tell App Router which headers to vary the cache on, then it would return the appropriate
Varyheader and cacheableCache-Controlheaders?Any other workarounds or better approaches?
Beta Was this translation helpful? Give feedback.
All reactions