@@ -215,10 +215,12 @@ generator's `constants.mjs`), so that the page and the library share one Preact.
215215` buildClient` receives ` { entry, virtualImports, config }` . The client ` entry`
216216is a single program shared by every page . It must be bundled into
217217` config.output` and the call must return
218- ` { scripts, preloads, stylesheets }` : paths relative to the output root of the
219- module scripts to load, the chunks they statically import (rendered as
220- ` modulepreload` hints), and the stylesheets . The generator renders those into
221- every page, resolved against the page' s location.
218+ ` { scripts, preloads, stylesheets, fonts }` : paths relative to the output root
219+ of the module scripts to load, the chunks they statically import (rendered as
220+ ` modulepreload` hints), the stylesheets, and optionally the fonts to preload.
221+ The generator renders those into every page, resolved against the page' s
222+ location. Name every file after its content (a hash), so hosts can cache them
223+ indefinitely (see [Publishing](../../../docs/publishing.md#cache-the-assets)).
222224
223225`config` is the resolved `html` configuration. The adapter must compile the
224226generated Preact JSX and CSS imports and resolve the supplied theme aliases and
@@ -309,9 +311,10 @@ plugins see and can transform every module of the client and server builds but
309311never the HTML pages. Customize the pages through the
310312[HTML template](#html-template) instead.
311313
312- The adapter reads the client asset names from Vite's manifest. A manifest is
313- written either way; pass ` build: { manifest: true }` (or a file name) to
314- ` createViteBundler` to keep it in the output for another tool.
314+ The adapter reads the client asset names from Vite's manifest, including the
315+ hashed names of the fonts to preload. A manifest is written either way; pass
316+ ` build: { manifest: true }` (or a file name) to ` createViteBundler` to keep it
317+ in the output for another tool.
315318
316319The adapter is only ever used on the main thread, so function-valued plugins
317320and hooks are supported. Worker threads receive the ` html ` configuration with
@@ -488,7 +491,11 @@ The HTML template file (set via `templatePath`) uses JavaScript template literal
488491- `dehydrated` {string} Server-rendered HTML for the page content.
489492- `assets` {string} The `<script>` and `<link>` tags loading the client
490493 assets, resolved against this page's location.
491- - `speculationRules` {string} Speculation rules JSON for prefetching.
494+ - `preloads` {string} The preload hints for the fonts the bundler reported.
495+ - `speculationRules` {string} Speculation rules JSON that prefetches the
496+ same-origin links leaving the site when they are hovered or pressed. Links
497+ within the site navigate client-side instead (see
498+ [Client-side navigation](#client-side-navigation)).
492499- `themeScript` {string} Inline script that applies the saved theme before paint.
493500- `root` {string} Relative or absolute path to the site root.
494501- `metadata` {Object} Full page metadata (frontmatter, path, heading, etc.).
@@ -505,3 +512,38 @@ Since the template supports arbitrary JS expressions, you can use conditionals a
505512The populated page is the final HTML: it is minified when `minify` is set and
506513written as is. Put `${assets}` in the `<head>`, or the page loads no script and
507514no stylesheet.
515+
516+ ## Client-side navigation
517+
518+ The site moves between its own pages client-side, through the
519+ [Navigation API](https://developer.mozilla.org/docs/Web/API/Navigation_API):
520+ following a link to another page fetches that page and swaps it into the
521+ current document instead of loading a new one. Scripts, stylesheets and fonts
522+ stay loaded, the search index and the remote config are fetched once per visit,
523+ and the sidebar keeps its scroll position. Back and forward, scroll restoration
524+ and focus behave as they do for full loads, and the old page cross-fades into
525+ the new one where view transitions are supported.
526+
527+ Pages are prefetched into memory when a link is hovered (unless the browser
528+ asks to save data) or pressed, so most navigations do not wait on the network.
529+
530+ Everything else is a regular navigation: links outside the site (including
531+ other versions of the docs), files that are not pages (such as the JSON and
532+ Markdown renderings), and every navigation in a browser without the Navigation
533+ API. So is a page that loads scripts or stylesheets the current one did not,
534+ such as one from a newer deployment.
535+
536+ When customizing the site, keep in mind that:
537+
538+ - The whole `<body>` is replaced, and scripts in it do not run. Of the
539+ `<head>`, only the `<title>` and the page-specific tags follow the page:
540+ `<meta>` tags, and `<link>` tags other than stylesheets and preloads (such as
541+ `canonical`).
542+ - Islands are unmounted and hydrated again on every page. Anything shared
543+ across pages belongs in module scope, which lasts for the whole visit. An
544+ island that scrolls keeps its position when the next page renders it too.
545+ - Once the document has navigated client-side, the `<html>` element has a
546+ `data-navigated` attribute, for styles that only belong on the first page,
547+ such as entry animations.
548+ - Analytics can count client-side page views through the Navigation API's
549+ `navigatesuccess` event.
0 commit comments