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

script标签中defer和async的区别 #19

Open
conan1992 opened this issue Jun 16, 2020 · 0 comments
Open

script标签中defer和async的区别 #19

conan1992 opened this issue Jun 16, 2020 · 0 comments

Comments

@conan1992
Copy link
Owner

conan1992 commented Jun 16, 2020

默认情况下:脚本的下载和执行是按照文档顺序同步进行的,脚本下载和执行时,会阻塞文档的解析;当脚本下载和执行完毕时才会继续文档解析;

async

当script标签中有async,脚本加载和文档加载异步执行的,当脚本下载完会停止html解析,执行脚本,等脚本执行完再继续html解析;

defer

当script标签中有defer,脚本加载和文档加载异步执行的,当文档解析完毕后触发DOMContentLoaded 事件前执行;

  • async和defer同时存在时结果和async一样;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant