Preload
Table of Contents
Preload (<link rel="preload">) is a browser optimization that allows critical resources (that may be discovered late) to be requested earlier. If you are comfortable thinking about how to manually order the loading of your key resources, it can have a positive impact on loading performance and metrics in the Core Web Vitals. That said, preload is not a panacea and requires an awareness of some trade-offs.
When to Use
- Use this when critical resources (fonts, scripts, images) are discovered late in the loading process
- This is helpful for improving Time To Interactive (TTI) and Largest Contentful Paint (LCP)
When NOT to Use
- For non-critical resources — preloading too many assets delays the resources that actually matter for initial render
- When resources are already discovered early by the browser's preload scanner (e.g., inline
<script>tags in<head>) - When overuse leads to browser warnings about unused preloaded resources, indicating wasted bandwidth
Instructions
- Use
<link rel="preload">for resources needed immediately on the current page - Be careful not to delay First Contentful Paint by preloading too many resources
- Use
asattribute to specify the resource type (script, style, font, image) - For fonts and other CORS-fetched resources, set
crossoriginon the preload to match the eventual request mode - Only preload resources that must be visible within ~1 second of initial render
Details
<link rel="preload" href="emoji-picker.js" as="script">
...
</head>
<body>
...
<script src="stickers.js" defer></script>
<script src="video-sharing.js" defer></script>
<script src="emoji-picker.js" defer></script>
When optimizing for metrics like Time To Interactive or First Input Delay, preload can be useful to load JavaScript bundles (or chunks) that are necessary for interactivity. Keep in mind that great care is needed when using preload as you want to avoid improving interactivity at the cost of delaying resources (like hero images or fonts) necessary for First Contentful Paint or Largest Contentful Paint.
If you are trying to optimize the loading of first-party JavaScript, you can also consider using <script defer> in the document <head> vs. <body> to help with early discover of these resources.
Preload in single-page apps
While prefetching is a great way to cache resources that may be requested some time soon, we can preload resources that need to be used instantly. Maybe it's a certain font that is used on the initial render, or certain images that the user sees right away.
Say our EmojiPicker component should be visible instantly on the initial render. Although it should not be included in the main bundle, it _should_ get loaded in parallel. Just like _prefetch_, we can add a magic comment in order to let Webpack know that this module should be preloaded.
const EmojiPicker = import(/* webpackPreload: true */ "./EmojiPicker");
Webpack 4.6.0+ allows preloading of resources by adding
/* webpackPreload: true */to the import. In order to make preloading work in older versions of webpack, you'll need to add the