Skip to content

Commit ef53907

Browse files
authored
docs(vite): document asset prefetching (#2308)
1 parent 05c7376 commit ef53907

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎docs/2-features/02-asset-bundling.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Asset bundling
33
description: "Web applications usually need to serve assets to users. Tempest provide a seamless integration with Vite, the most popular front-end development server and build tool"
4-
keywords: ["vite", "frontend", "js", "css", "ts", "typescript", "javascript", "sri", "manifest", "assets"]
4+
keywords: ["vite", "frontend", "js", "css", "ts", "typescript", "javascript", "sri", "manifest", "assets", "prefetch"]
55
---
66

77
## Overview
@@ -102,6 +102,21 @@ By default, assets are compiled in the `public/build` directory. This directory
102102
This directory is already in your `.gitignore` if you used the `{sh}php tempest install vite` command.
103103
:::
104104

105+
## Prefetching assets
106+
107+
Tempest can instruct the browser to prefetch lazily loaded chunks in the background, so the user doesn't have to wait for them to download later. To enable it, configure the `prefetching` parameter in a `vite.config.php` file:
108+
109+
```php app/vite.config.php
110+
return new ViteConfig(
111+
prefetching: new PrefetchConfig(
112+
strategy: PrefetchStrategy::WATERFALL,
113+
concurrent: 3,
114+
),
115+
);
116+
```
117+
118+
The `WATERFALL` strategy downloads `concurrent` assets at a time, while `AGGRESSIVE` downloads all of them at once. Prefetching starts on the `load` event by default, which you may change with the `prefetchEvent` parameter.
119+
105120
## Using a `nonce` attribute
106121

107122
If your application uses a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP), you may need to include `nonce` attributes to the tags generated by `{html}<x-vite-tags />`.

0 commit comments

Comments
 (0)