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

哪些地方会出现css阻塞,哪些地方会出现js阻塞? #59

Open
Sogrey opened this issue Apr 26, 2019 · 0 comments
Open

哪些地方会出现css阻塞,哪些地方会出现js阻塞? #59

Sogrey opened this issue Apr 26, 2019 · 0 comments

Comments

@Sogrey
Copy link
Owner

Sogrey commented Apr 26, 2019

js的阻塞特性:所有浏览器在下载JS下载、解析、执行完毕后才开始继续JS,但是 由于浏览器为了防止出现DOM树,需要重新构建 嵌入JS只会阻塞其后内容的显示,2种方式都会阻塞其后资源的下载。也就是说外部样式不会阻塞外部脚本的加载,但会阻塞外部脚本的执行。

CSS本来是可以并行下载的,在什么情况下会出现阻塞加载了(在测试观察中,CSS都是阻塞加载)

JS的时候,该JS放到 根本原因:因为浏览器会维持css和JS会阻塞后面的资源加载,所以就会出现上面 嵌入 1、放在底部,虽然放在底部照样会阻塞所有呈现,但不会阻塞资源下载。 2、如果嵌入JS放在head中,请把嵌入JS放在CSS头部。 3、使用defer(只支持IE) 4、不要在嵌入的JS中调用运行时间较长的函数,如果一定要用,可以用setTimeout来调用

@Sogrey Sogrey added this to css in Web面经题 Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant