高级前端
dom
【Q284】prefetch 与 preload 的区别是什么

prefetch 与 preload 的区别是什么

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 286 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

<link rel="prefetch" href="style.css" as="style" />
<link rel="preload" href="main.js" as="script" />
  1. preload 加载当前路由必需资源,优先级高。一般对于 Bundle Spliting 资源与 Code Spliting 资源做 preload
  2. prefetch 优先级低,在浏览器 idle 状态时加载资源。一般用以加载其它路由资源,如当页面出现 Link,可 prefetch 当前 Link 的路由资源。(next.js 默认会对 link 做懒加载+prefetch,即当某条 Link 出现页面中,即自动 prefetch 该 Link 指向的路由资源

prefetch - Prefetch the page in the background. Defaults to true. Any that is in the viewport (initially or through scroll) will be preloaded.

更多信息可参考以下链接: