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

异步加载 js 脚本的方法有哪些? #5

Open
into-piece opened this issue Jun 20, 2019 · 0 comments
Open

异步加载 js 脚本的方法有哪些? #5

into-piece opened this issue Jun 20, 2019 · 0 comments

Comments

@into-piece
Copy link
Owner

  1. 动态创建script标签,可通过script的onreadyState监视加载。
  2. html5新增的async属性:可跟其他内容并行下载,限制ie9以上,只能加载外部js脚本。
  3. html4的defer,作用与async相同,兼容更好一点,但async只要加载完可立即执行,defer需等待在dom加载完毕后执行,在window.onload之前,其他没有添加defer属性的script标签之后。
  4. 利用XHR异步加载js内容并执行。
  5. iframe方式。
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