You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/10-getting-started/10-introduction.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ title: Introduction
12
12
13
13
SvelteKit is a framework for building extremely high-performance web apps.
14
14
15
-
Building an app with all the modern best practices is fiendishly complicated. Those practices include [build optimizations](https://vitejs.dev/guide/features.html#build-optimizations), so that you load only the minimal required code; [offline support](/docs/service-workers); [prefetching](/docs/link-options#data-sveltekit-prefetch) pages before the user initiates navigation; and [configurable rendering](/docs/page-options) that allows you to render your app [on the server](/docs/glossary#ssr) or [in the browser](/docs/glossary#csr-and-spa) at runtime or [at build-time](/docs/glossary#prerendering). SvelteKit does all the boring stuff for you so that you can get on with the creative part.
15
+
Building an app with all the modern best practices is fiendishly complicated. Those practices include [build optimizations](https://vitejs.dev/guide/features.html#build-optimizations), so that you load only the minimal required code; [offline support](/docs/service-workers); [preloading](/docs/link-options#data-sveltekit-preload-data) pages before the user initiates navigation; and [configurable rendering](/docs/page-options) that allows you to render your app [on the server](/docs/glossary#ssr) or [in the browser](/docs/glossary#csr-and-spa) at runtime or [at build-time](/docs/glossary#prerendering). SvelteKit does all the boring stuff for you so that you can get on with the creative part.
16
16
17
17
It uses [Vite](https://vitejs.dev/) with a [Svelte plugin](https://github.com/sveltejs/vite-plugin-svelte) to provide a lightning-fast and feature-rich development experience with [Hot Module Replacement (HMR)](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#hot), where changes to your code are reflected in the browser instantly.
Copy file name to clipboardExpand all lines: documentation/docs/30-advanced/30-link-options.md
+45-12
Original file line number
Diff line number
Diff line change
@@ -6,20 +6,53 @@ In SvelteKit, `<a>` elements (rather than framework-specific `<Link>` components
6
6
7
7
You can customise the behaviour of links with `data-sveltekit-*` attributes. These can be applied to the `<a>` itself, or to a parent element.
8
8
9
-
### data-sveltekit-prefetch
9
+
### data-sveltekit-preload-data
10
10
11
-
To get a head start on importing the code and fetching the page's data, use the `data-sveltekit-prefetch` attribute, which will start loading everything as soon as the user hovers over the link (on a desktop) or touches it (on mobile), rather than waiting for the `click` event to trigger navigation. Typically, this buys us an extra couple of hundred milliseconds, which is the difference between a user interface that feels laggy, and one that feels snappy.
11
+
Before the browser registers that the user has clicked on a link, we can detect that they've hovered the mouse over it (on desktop) or that a `touchstart` or `mousedown` event was triggered. In both cases, we can make an educated guess that a `click` event is coming.
12
12
13
-
To apply this behaviour across the board, add the attribute to a parent element (or even the `<body>` in your `src/app.html`):
13
+
SvelteKit can use this information to get a head start on importing the code and fetching the page's data, which can give us an extra couple of hundred milliseconds — the difference between a user interface that feels laggy and one that feels snappy.
14
+
15
+
We can control this behaviour with the `data-sveltekit-preload-data` attribute, which can have one of two values:
16
+
17
+
-`"hover"` means that preloading will start if the mouse comes to a rest over a link. On mobile, preloading begins on `touchstart`
18
+
-`"tap"` means that preloading will start as soon as a `touchstart` or `mousedown` event is registered
19
+
20
+
The default project template has a `data-sveltekit-preload-data="hover"` attribute applied to the `<body>` element in `src/app.html`, meaning that every link is preloaded on hover by default:
Sometimes, calling `load` when the user hovers over a link might be undesirable, either because it's likely to result in false positives (a click needn't follow a hover) or because data is updating very quickly and a delay could mean staleness.
29
+
30
+
In these cases, you can specify the `"tap"` value, which causes SvelteKit to call `load` only when the user taps or clicks on a link:
> You can also programmatically invoke `prefetch` from `$app/navigation`.
38
+
> You can also programmatically invoke `preloadData` from `$app/navigation`.
39
+
40
+
Data will never be preloaded if the user has chosen reduced data usage, meaning [`navigator.connection.saveData`](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/saveData) is `true`.
41
+
42
+
### data-sveltekit-preload-code
43
+
44
+
Even in cases where you don't want to preload _data_ for a link, it can be beneficial to preload the _code_. The `data-sveltekit-preload-code` attribute works similarly to `data-sveltekit-preload-data`, except that it can take one of four values, in decreasing 'eagerness':
45
+
46
+
-`"eager"` means that links will be preloaded straight away
47
+
-`"viewport"` means that links will be preloaded once they enter the viewport
48
+
-`"hover"` - as above, except that only code is preloaded
49
+
-`"tap"` - as above, except that only code is preloaded
50
+
51
+
Note that `viewport` and `eager` only apply to links that are present in the DOM immediately following navigation — if a link is added later (in an `{#if ...}` block, for example) it will not be preloaded until triggered by `hover` or `tap`. This is to avoid performance pitfalls resulting from aggressively observing the DOM for changes.
52
+
53
+
> Since preloading code is a prerequisite for preloading data, this attribute will only have an effect if it specifies a more eager value than any `data-sveltekit-preload-data` attribute that is present.
54
+
55
+
As with `data-sveltekit-preload-data`, this attribute will be ignored if the user has chosen reduced data usage.
23
56
24
57
### data-sveltekit-reload
25
58
@@ -50,14 +83,14 @@ In certain cases, you may wish to disable this behaviour. Adding a `data-sveltek
50
83
To disable any of these options inside an element where they have been enabled, use the `"off"` value:
Copy file name to clipboardExpand all lines: documentation/docs/60-appendix/10-migrating.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ Your custom error page component should be renamed from `_error.svelte` to `+err
85
85
86
86
#### Imports
87
87
88
-
The `goto`, `prefetch` and `prefetchRoutes` imports from `@sapper/app` should be replaced with identical imports from [`$app/navigation`](/docs/modules#$app-navigation).
88
+
The `goto`, `prefetch` and `prefetchRoutes` imports from `@sapper/app` should be replaced with `goto`, `preloadData` and `preloadCode`imports respectively from [`$app/navigation`](/docs/modules#$app-navigation).
89
89
90
90
The `stores` import from `@sapper/app` should be replaced — see the [Stores](/docs/migrating#pages-and-layouts-stores) section below.
91
91
@@ -133,7 +133,7 @@ This caused problems and is no longer the case in SvelteKit. Instead, relative U
133
133
134
134
#### <a> attributes
135
135
136
-
-`sapper:prefetch` is now `data-sveltekit-prefetch`
136
+
-`sapper:prefetch` is now `data-sveltekit-preload-data`
137
137
-`sapper:noscroll` is now `data-sveltekit-noscroll`
0 commit comments