docs: clarify that preloads are sent as a Link header on dynamically rendered pages#16309
docs: clarify that preloads are sent as a Link header on dynamically rendered pages#16309Nic-Polumeyv wants to merge 3 commits into
Link header on dynamically rendered pages#16309Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/c7528c901eca5caccdf40122d333d883b764c663Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
|
|
Thanks! Can you rebase this on the |
…y rendered pages
573ffdf to
7d59e63
Compare
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
| - `transformPageChunk(opts: { html: string, done: boolean }): MaybePromise<string | undefined>` — 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 files should be added to the `<head>` 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. Note that in dev mode `preload` is _not_ called, since it depends on analysis that happens at build time. Preloading can improve performance by downloading assets sooner, but it can also hurt if too much is 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. | ||
| - `preload(input: { type: 'js' | 'css' | 'font' | 'asset', path: string }): boolean` — determines which files should be preloaded. When a page is rendered dynamically, files are preloaded via the [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link); prerendered pages have `<link>` tags added to the `<head>` tag instead. 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. Note that in dev mode `preload` is _not_ called, since it depends on analysis that happens at build time. Preloading can improve performance by downloading assets sooner, but it can also hurt if too much is 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. |
There was a problem hiding this comment.
closes #16139
The
preloaddocs say the selected files "should be added to the<head>tag". Since #14200 that only happens for prerendered pages. Dynamically rendered pages send aLinkresponse header instead, with no tag in the HTML.The old wording produced #16139. The reporter enabled font preloading, searched the served HTML for a
<link rel="preload" as="font">tag, and reasonably concluded the feature was broken. Running their reproduction, the font was preloaded the whole time:This updates the hooks docs and the
ResolveOptionsJSDoc to name both delivery paths.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits