Skip to content

Commit 6617caa

Browse files
committed
docs: split the redirect caching example in two and add FHachez in the list of contributors of the doc.
1 parent 4415d80 commit 6617caa

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/docs/src/routes/docs/(qwikcity)/caching/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ contributors:
1111
- chsanch
1212
- hamatoyogi
1313
- Jemsco
14+
- FHachez
1415
updated_at: '2023-10-03T18:53:23Z'
1516
created_at: '2023-05-24T03:52:24Z'
1617
---

packages/docs/src/routes/docs/(qwikcity)/guides/redirects/index.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ contributors:
77
- mhevery
88
- mrhoodz
99
- hamatoyogi
10+
- FHachez
1011
updated_at: '2023-06-25T19:43:33Z'
1112
created_at: '2023-03-20T23:45:13Z'
1213
---
@@ -60,10 +61,16 @@ When you issue a redirect using the `redirect()` method from the `RequestEvent`,
6061
If the redirect's status code is greater than `301` (e.g., `302`, `307`), and you haven't called `cacheControl()` for that request, the `Cache-Control` header will automatically be set to `'no-store'`. This prevents the redirect from being cached by the browser or intermediate caches.
6162

6263
```typescript
63-
export const onGet: RequestHandler = ({ redirect, cacheControl }) => {
64-
// This will result in a `Cache-Control: no-store` header except if cacheControl was called in a middleware or layout above.
64+
export const onGet: RequestHandler = ({ redirect }) => {
65+
// This will result in a `Cache-Control: no-store` header
6566
throw redirect(302, '/new-location');
67+
};
68+
```
6669

70+
To override this default behavior and explicitly set a cache control policy for a redirect, you can call `cacheControl()` before throwing the redirect.
71+
72+
```typescript
73+
export const onGet: RequestHandler = ({ redirect, cacheControl }) => {
6774
// To override the default, set it explicitly
6875
cacheControl('day');
6976
throw redirect(302, '/new-location');

0 commit comments

Comments
 (0)