HTML 资源预加载

Tags
html
Created
May 23, 2016 3:59 AM

浏览器有黑魔法预解析加载:https://www.w3cplus.com/javascript/building-the-dom-faster-speculative-parsing-async-defer-and-preload.html

DNS-prefetch、subresource 和 标准的 prefetch、preconnect、prerender、preload

<link rel="dns-prefetch" href="//example.com”>

<link rel="preconnect" href="http://example.com"> <!-- 不仅完成 DNS 预解析,同时还将进行 TCP 握手和建立传输层协议  —>

<link rel="prefetch" href="image.png"> <!-- 预获取资源,某些预获取可能会被浏览器忽略,例如从一个非常缓慢的网络中获取一个庞大的字体文件。并且,Firefox 只会在浏览器闲置时进行资源预获取,遵从link的crossorigin属性 —>

<link rel="subresource" href="styles.css"> <!-- 高优先级的资源预加载。在所有 prefetch 项之前进行  —>

<link rel="prerender" href="http://example.com">  <!--预先加载指定文档的所有资源  —>

<link rel="preload" href="image.png"> <!--与 prefetch 不同(可能被忽略)的是,浏览器一定会预加载该资源, 而且是高优先级  —>

https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types

Chrome has four caches: the HTTP cache, memory cache, Service Worker cache & Push cache. Both preload and prefetched resources are stored in the HTTP cache.

SuperMade with Super