Skip to content

Commit 2df17df

Browse files
committed
fix(qwik-city): don't use stale-while-revalidate
1 parent eea117b commit 2df17df

File tree

11 files changed

+7
-51
lines changed

11 files changed

+7
-51
lines changed

.changeset/gentle-bats-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik-city': minor
3+
---
4+
5+
FIX: qwik-city no longer forces `q-data.json` downloads, instead relying on the cache headers. This means that you have to make sure your `q-data.json` is served with `Cache-Control` headers that suit you. That file contains all the information about the route and is read for each qwik-city navigation. By default the data is cached for one hour.

packages/docs/public/_headers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
Cache-Control: public, max-age=604800, s-maxage=604800
1212

1313
/*
14-
Cache-Control: public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400
14+
Cache-Control: public, max-age=3600, s-maxage=3600

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ created_at: '2023-05-24T03:52:24Z'
1919

2020
Caching responses is critical for keeping your site as fast as possible, both for [pages](/docs/(qwikcity)/pages/index.mdx) as well as [middleware](/docs/(qwikcity)/middleware/index.mdx).
2121

22-
A good default is to use [stale-while-revalidate](https://web.dev/stale-while-revalidate/) caching for all responses.
22+
A option is to use [stale-while-revalidate](https://web.dev/stale-while-revalidate/) caching for all responses. Note that this means that users will see a cached response even if the server is updated, and only when the user refreshes will they see the updated content.
2323

2424
For instance, we can add an `onGet` export to our root [layout](/docs/(qwikcity)/layout/index.mdx) (`src/routes/layout.tsx`) like so, to apply good caching defaults site-wide:
2525

packages/docs/src/routes/examples/[...id]/index!.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ export const onGet: RequestHandler = ({ cacheControl }) => {
178178
cacheControl({
179179
public: true,
180180
maxAge: 3600,
181-
sMaxAge: 3600,
182-
staleWhileRevalidate: 86400,
183181
});
184182
};
185183

packages/docs/src/routes/layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ export const onGet: RequestHandler = ({ cacheControl }) => {
1010
cacheControl({
1111
public: true,
1212
maxAge: 3600,
13-
sMaxAge: 3600,
14-
staleWhileRevalidate: 86400,
1513
});
1614
};

packages/docs/src/routes/playground/index!.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,5 @@ export const onGet: RequestHandler = ({ cacheControl }) => {
135135
cacheControl({
136136
public: true,
137137
maxAge: 3600,
138-
sMaxAge: 3600,
139-
staleWhileRevalidate: 86400,
140138
});
141139
};

packages/docs/src/routes/tutorial/layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,5 @@ export const onGet: RequestHandler = ({ cacheControl }) => {
172172
cacheControl({
173173
public: true,
174174
maxAge: 3600,
175-
sMaxAge: 3600,
176-
staleWhileRevalidate: 86400,
177175
});
178176
};

packages/qwik-city/src/middleware/request-handler/cache-control.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export function createCacheControl(cacheControl: CacheControl) {
2020
public: true,
2121
immutable: true,
2222
maxAge: 60 * 60 * 24 * 365,
23-
staleWhileRevalidate: 60 * 60 * 24 * 365,
2423
};
2524
} else if (cacheControl === 'no-cache') {
2625
cacheControl = {
@@ -32,7 +31,6 @@ export function createCacheControl(cacheControl: CacheControl) {
3231
cacheControl = {
3332
maxAge: cacheControl,
3433
sMaxAge: cacheControl,
35-
staleWhileRevalidate: cacheControl,
3634
};
3735
}
3836

starters/apps/empty/src/routes/layout.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

starters/apps/playground/src/routes/layout.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ import Footer from "../components/starter/footer/footer";
77

88
import styles from "./styles.css?inline";
99

10-
export const onGet: RequestHandler = async ({ cacheControl }) => {
11-
// Control caching for this request for best performance and to reduce hosting costs:
12-
// https://qwik.dev/docs/caching/
13-
cacheControl({
14-
// Always serve a cached response by default, up to a week stale
15-
staleWhileRevalidate: 60 * 60 * 24 * 7,
16-
// Max once every 5 seconds, revalidate on the server to get a fresh version of this page
17-
maxAge: 5,
18-
});
19-
};
20-
2110
export const useServerTimeLoader = routeLoader$(() => {
2211
return {
2312
date: new Date().toISOString(),

0 commit comments

Comments
 (0)