undefined | true | PrefetchOptions
undefined
Inject the <link rel="prefetch">
tags for the static assets generated by Rsbuild.
The prefetch keyword for the rel attribute of the <link>
element provides a hint to browsers that the user is likely to need the target resource for future navigation, and therefore the browser can likely improve the user experience by preemptively fetching and caching the resource.
When performance.prefetch
is set to true
, Rsbuild will use the following default options to prefetch resources. This means prefetching all async resources on the current page, including async JS and its associated CSS, image, font, and other resources.
For example, if you dynamically import other modules in the entry file:
The tags injected in HTML are as follows:
The performance.prefetch
can only inject the prefetch tags for static resources generated by Rsbuild. If you need to prefetch other resources, you can manually add tags through html.tags :
The injected HTML tag is as follows:
performance.prefetch
can be set to an object to specify the options.
'async-chunks' | 'initial' | 'all-assets' | 'all-chunks'
'async-chunks'
Specify which types of resources will be included. Currently supported values are as follows:
async-chunks
: Includes all async resources on the current page, such as async JS chunks, and its associated CSS, images, fonts, and other static resources.initial
: Includes all non-async resources on the current page.all-chunks
: Includes all async and non-async resources on the current page.all-assets
: Includes all resources from all pages.For example, to include all png images on the current page, configure it as follows:
If a script has been directly referenced via HTML <script>
tag, it will not be prefetched.
undefined
A extra filter to determine which resources to include.
include
is a regular expression, it will be used directly to match the filename:include
is a string, it will be converted to a regular expression to match the filename:include
is a function, it will be called with the filename as an argument:include
is an array, it can contain multiple filters, and the filename only needs to match one of the filters to be included:undefined
A extra filter to determine which resources to exclude, the usage is similar to include
.