Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

资源预加载 #5547

Open
wssgcg1213 opened this issue Nov 14, 2022 · 1 comment
Open

资源预加载 #5547

wssgcg1213 opened this issue Nov 14, 2022 · 1 comment
Assignees
Labels

Comments

@wssgcg1213
Copy link
Collaborator

原计划将页面依赖的 JS 资源,通过 preload 的方式进行预加载

image

ice-lab/ice-next#229

但实时上,浏览器在下载完 HTML 后,HTML 中声明的 link 和 script 资源会被立即发起请求,且是并行的,而非按顺序边解析,边加载。

所以将 body 中的 script 内容前置到 head 中,使用 preload,并不会提前资源的加载时机。

通过 preload 可能带来较大收益的场景是:

  • 提前发起 CSS 资源内依赖的 fonts / images
  • 大的图片或视频资源
  • 异步加载的 js 资源

更多讨论见 ice-lab/ice-next#230

@chenjun1011
Copy link
Collaborator

按 Chrome 对的说法,Preload 适用于配置一些不容易被识别的关键资源,例如:样式中的字体文件、背景图、异步加载的脚本

https://web.dev/fetch-priority/

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants