defer与async的认识
defer跟asyns都是脚本外联文件的标签属性(标签内的脚本不会执行),加了这两个属性其中一个那么脚本文件会异步加载执行。
首先检查defer在浏览器中执行顺序(检查浏览器为chome,firfox,ie)
defer:
在编译器中输入代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>defer async</title>
<style>
</style>
<script type="text/javascript">
console.log("head内嵌js")
</script>
</head>
<body>
<img src="../images/1.jpg" alt="1.jpg" οnlοad="console.log('img')" />
<script type="text/javascript" src="js/defer.js" defer="defer"></script>
<script type="text/javascript">
window.onload = function(){
console.log("onload")
}
console.log("内嵌js")
</script>
</body>
</html>
在chome,firfox的控制台中,输出先后顺序为
head内嵌js
img
内嵌js
this is defer
onload
Browser Support
The defer attribute is supported in all major browsers.
Browser Support
The async attribute is supported in Internet Explorer 10, Firefox, Opera, Chrome, and Safari.
Note: The async attribute of the <script> tag is not supported in Internet Explorer 9 and earlier versions.
转载于:https://www.cnblogs.com/outside/p/3723722.html
总结
以上是生活随笔为你收集整理的defer与async的认识的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: ES权威指南[官方文档学习笔记]-8
- 下一篇: selenium+ant+testng测