Preloading web resources
The browser loads and processes resources sequentially. Using the link element, you can tell the browser that the resource will be needed soon. And then the browser will download and save it to the cache.
<link rel="preload" href="/css/defualt.css" as="style">
<link rel="preload" href="/js/site.js" as="script">
<link rel="preload" href="/video/myvidos.mp4" as="video" type="video/mp4">
<link rel="preload" href="fonts/cicle_fina-webfont.woff2"
as="font" type="font/woff2" crossorigin>
<!-- and below use resources as usual -->
<link rel="stylesheet" href="/css/defualt.css">
...
You don't need preload all resources, only critical. If browser has developer tools, you can check the console log after reloading page. For example, Chrome will log message like this:
The resource url_resource was preloaded using link preload but not used within a few seconds from the window's load event."
attributes
attribute | description |
---|---|
rel | Possible values are:
|
href | Url of resource. |
as | Specifies the type of resource. Used by browser
|
crossorigin | Indicates whether CORS must be used when fetching the resource. For some reasons it is also used for preloading fonts even that not are cross-origin. |