Skip to content

Commit 51f7967

Browse files
authored
docs: add info about caching pages with different domains (#3793)
1 parent b67b37d commit 51f7967

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

docs/content/docs/02.guide/09.different-domains.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,27 @@ The same requests when using the `'prefix_except_default'`{lang="ts-type"} strat
169169
- https://mydomain.com/pl -> https://mydomain.com/pl (pl language)
170170
- https://mydomain.com/ua -> https://mydomain.com/ua (ua language)
171171
- https://es.mydomain.com -> https://es.mydomain.com (es language)
172-
- https://fr.mydomain.com -> https://fr.mydomain.com (fr language)
172+
- https://fr.mydomain.com -> https://fr.mydomain.com (fr language)
173+
174+
## Caching considerations with different domains
175+
176+
When using different domains, make sure to configure caching properly so that
177+
responses are correctly separated per domain.
178+
179+
Because the same route may be served under multiple domains (e.g. `en.mydomain.com`
180+
and `fr.mydomain.com`), caches need to vary by the request host. Otherwise,
181+
a response generated for one domain could be reused on another, causing the wrong language to render,
182+
leading to hydration mismatches and visible flashes on the client.
183+
184+
The recommended setup is to use `cache.varies: ['host']` in your route rules,
185+
so that the `host` header is included in the cache key:
186+
187+
```diff [nuxt.config.ts]
188+
export default defineNuxtConfig({
189+
routeRules: {
190+
- '/': { swr: 60 },
191+
+ '/': { swr: 60, cache: { varies: ['host'] } },
192+
},
193+
// ...
194+
})
195+
```

0 commit comments

Comments
 (0)