firstly 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# firstly
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#335](https://github.com/jycouet/firstly/pull/335) [`c551a73`](https://github.com/jycouet/firstly/commit/c551a730969252e89b0a1d1a59a54580a380237b) Thanks [@jycouet](https://github.com/jycouet)! - Add `handleCaching` (`firstly/svelte/server`): a `hooks.server.js` handle setting deploy-safe `Cache-Control` headers - immutable for `/_app/immutable/*` 200s, no-store for HTML/API and all non-200s (a cached 404 chunk would brick the client until "disable cache").
|
|
8
|
+
|
|
3
9
|
## 0.8.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Handle } from '@sveltejs/kit';
|
|
2
|
+
/**
|
|
3
|
+
* `hooks.server.js` handle that sets `Cache-Control` so browsers and CDNs cache
|
|
4
|
+
* correctly across deploys - the server-side twin of `withStaleDeployReload`.
|
|
5
|
+
*
|
|
6
|
+
* - `/_app/immutable/*` (200 only) → `public, max-age=31536000, immutable`.
|
|
7
|
+
* Only this subtree is content-hashed; `/_app/version.json` and `/_app/env.js`
|
|
8
|
+
* are not, and MUST stay revalidatable or clients never see a new deploy.
|
|
9
|
+
* - Everything else non-asset (HTML, API) and every non-200 → `no-cache, no-store,
|
|
10
|
+
* must-revalidate`. Never let a 404 carry a long max-age: a chunk 404 during a
|
|
11
|
+
* deploy window cached for a year bricks that client until devtools "disable cache".
|
|
12
|
+
* - Other static assets (200, by extension) are left untouched for you to tune.
|
|
13
|
+
*
|
|
14
|
+
* Replaces purge-everything-on-deploy CDN strategies.
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* // src/hooks.server.js
|
|
18
|
+
* import { sequence } from '@sveltejs/kit/hooks'
|
|
19
|
+
* import { handleCaching } from './'
|
|
20
|
+
*
|
|
21
|
+
* export const handle = sequence(handleCaching, ...rest)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const handleCaching: Handle;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Cacheable static assets by extension (used to skip the no-cache header).
|
|
2
|
+
const STATIC_ASSET_RE = /\.(js|css|ico|png|jpg|jpeg|gif|svg|webp|avif|woff2?|ttf|eot)$/;
|
|
3
|
+
/**
|
|
4
|
+
* `hooks.server.js` handle that sets `Cache-Control` so browsers and CDNs cache
|
|
5
|
+
* correctly across deploys - the server-side twin of `withStaleDeployReload`.
|
|
6
|
+
*
|
|
7
|
+
* - `/_app/immutable/*` (200 only) → `public, max-age=31536000, immutable`.
|
|
8
|
+
* Only this subtree is content-hashed; `/_app/version.json` and `/_app/env.js`
|
|
9
|
+
* are not, and MUST stay revalidatable or clients never see a new deploy.
|
|
10
|
+
* - Everything else non-asset (HTML, API) and every non-200 → `no-cache, no-store,
|
|
11
|
+
* must-revalidate`. Never let a 404 carry a long max-age: a chunk 404 during a
|
|
12
|
+
* deploy window cached for a year bricks that client until devtools "disable cache".
|
|
13
|
+
* - Other static assets (200, by extension) are left untouched for you to tune.
|
|
14
|
+
*
|
|
15
|
+
* Replaces purge-everything-on-deploy CDN strategies.
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* // src/hooks.server.js
|
|
19
|
+
* import { sequence } from '@sveltejs/kit/hooks'
|
|
20
|
+
* import { handleCaching } from './'
|
|
21
|
+
*
|
|
22
|
+
* export const handle = sequence(handleCaching, ...rest)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const handleCaching = async ({ event, resolve }) => {
|
|
26
|
+
const response = await resolve(event);
|
|
27
|
+
const { pathname } = event.url;
|
|
28
|
+
if (pathname.startsWith('/_app/immutable/') && response.status === 200) {
|
|
29
|
+
response.headers.set('Cache-Control', 'public, max-age=31536000, immutable');
|
|
30
|
+
}
|
|
31
|
+
else if (response.status !== 200 || !STATIC_ASSET_RE.test(pathname)) {
|
|
32
|
+
response.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ServerLoadEvent } from '@sveltejs/kit';
|
|
2
|
+
export { handleCaching } from './handleCaching.js';
|
|
2
3
|
/**
|
|
3
4
|
* Wrap a SvelteKit SERVER load (`+page.server.ts`) so plain global `repo()` reads
|
|
4
5
|
* apply the API gate (as the current user) instead of the privileged DB provider.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { withRemultFetch } from '../remultApiLoad.js';
|
|
2
|
+
export { handleCaching } from './handleCaching.js';
|
|
2
3
|
/**
|
|
3
4
|
* Wrap a SvelteKit SERVER load (`+page.server.ts`) so plain global `repo()` reads
|
|
4
5
|
* apply the API gate (as the current user) instead of the privileged DB provider.
|