diff --git a/.changeset/lucky-rocks-marry.md b/.changeset/lucky-rocks-marry.md new file mode 100644 index 000000000000..372a8cd6d747 --- /dev/null +++ b/.changeset/lucky-rocks-marry.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] don't preload fonts by default diff --git a/documentation/docs/30-advanced/20-hooks.md b/documentation/docs/30-advanced/20-hooks.md index 221d73d91174..62fa4a564746 100644 --- a/documentation/docs/30-advanced/20-hooks.md +++ b/documentation/docs/30-advanced/20-hooks.md @@ -72,7 +72,7 @@ You can add call multiple `handle` functions with [the `sequence` helper functio - `transformPageChunk(opts: { html: string, done: boolean }): MaybePromise` — applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML (they could include an element's opening tag but not its closing tag, for example) but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components. - `filterSerializedResponseHeaders(name: string, value: string): boolean` — determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`. By default, none will be included. -- `preload(input: { type: 'js' | 'css' | 'font' | 'asset', path: string }): boolean` — determines what should be added to the `` tag to preload it. Preloading can improve performance because things are downloaded sooner, but they can also hurt core web vitals because too many things may be downloaded unnecessarily. By default, `js`, `css` and `font` files will be preloaded. `asset` files are not preloaded at all currently, but we may add this later after evaluating feedback. +- `preload(input: { type: 'js' | 'css' | 'font' | 'asset', path: string }): boolean` — determines what files should be added to the `` tag to preload it. The method is called with each file that was found at build time while constructing the code chunks — so if you for example have `import './styles.css` in your `+page.svelte`, `preload` will be called with the resolved path to that CSS file when visiting that page. Preloading can improve performance because things are downloaded sooner, but they can also hurt core web vitals because too many things may be downloaded unnecessarily. By default, `js` and `css` files will be preloaded. `asset` files are not preloaded at all currently, but we may add this later after evaluating feedback. ```js /// file: src/hooks.server.js diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 397f28086662..0d13c055c66b 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -27,7 +27,7 @@ const default_transform = ({ html }) => html; const default_filter = () => false; /** @type {import('types').RequiredResolveOptions['preload']} */ -const default_preload = ({ type }) => type !== 'asset'; +const default_preload = ({ type }) => type === 'js' || type === 'css'; /** @type {import('types').Respond} */ export async function respond(request, options, state) {