undefined | true | PreloadOption
undefined
Inject the <link rel="preload">
tags for the static assets generated by Rsbuild.
The preload value of the <link>
element's rel attribute lets you declare fetch requests in the HTML's <head>
, specifying resources that your page will need very soon, which you want to start loading early in the page lifecycle, before browsers' main rendering machinery kicks in.
This ensures they are available earlier and are less likely to block the page's render, improving performance. Even though the name contains the term load, it doesn't load and execute the script but only schedules it to be downloaded and cached with a higher priority.
When performance.preload
is set to true
, Rsbuild will use the following default options to preload resources. This means preloading all asynchronous resources on the current page, including asynchronous 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.preload
can only inject the preload tags for static resources generated by Rsbuild. If you need to preload other resources, you can manually add tags through html.tags :
The injected HTML tag is as follows:
When the value of performance.preload
is object
type, the Rsbuild will enable the preload capability for the specified resource according to the current options.
'async-chunks' | 'initial' | 'all-assets' | 'all-chunks'
'async-chunks'
The type
field controls which resources will be pre-fetched, and supports secondary filtering of specified resources through include
and exclude
.
Currently supported resource types are as follows:
async-chunks
: preload all asynchronous resources (on the current page), including asynchronous JS and its associated CSS, image, font and other resources.initial
: preload all non-async resources (on the current page).all-chunks
: preload all resources (on the current page), including all asynchronous and non-asynchronous resources.all-assets
: preload all resources, and resources of other pages will be included in the MPA scenario.When you want to preload all image resources in png format on the current page, you can configure it as follows:
boolean
true
Whether to preload script resources that already exist in the current HTML template. By default, if a resource has been added to the current HTML via a script tag, it will not be preloaded additionally.
When set to true
, Rsbuild will generate preload tags for all eligible resources, even if these resources already exist in the HTML.