@@ -246,6 +246,55 @@ Layout to be recalculated, which is much more expensive. For details on this, se
If you _do_ need to change layout (for example, a sidebar that pushes main content over), prefer [FLIP](https://aerotwist.com/blog/flip-your-animations/). FLIP allows you to change expensive
properties once, and handle the actual animation with transforms.
### Prefetching assets
In addition to prefetching data from the [API](./graphql.md#making-initial-queries-early-with-graphql-startup-calls)
we allow prefetching the named Javascript "chunks" as
[defined in the Webpack configuration](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/webpack.config.js#L298-359).
We support two types of prefetching for the chunks:
- The [`prefetch` link type](https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/prefetch)
is used to prefetch a chunk for the future navigation
- The [`preload` link type](https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preloadh)
is used to prefetch a chunk that is crucial for the current navigation but is not
discovered until later in the rendering process
Both `prefetch` and `preload` links bring the loading performance benefit to the pages. Both are
fetched asynchronously, but contrary to [deferring the loading](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer)
of the assets which is used for other javascript resources in the product by default, `prefetch` and
`preload` neither parse nor execute the fetched script unless explicitly imported in any javascript
module. This allows to cache the fetched resources without blocking the execution of the
remaining page resources.
To prefetch a Javascript chunk in a HAML view, `:prefetch_asset_tags` with the combination of
the `webpack_preload_asset_tag` helper is provided:
```javascript
-content_for:prefetch_asset_tagsdo
-webpack_preload_asset_tag('monaco')
```
This snippet will add a new `<link rel="preload">` element into the resulting HTML page: