defer与async的认识
defer跟asyns都是腳本外聯(lián)文件的標簽屬性(標簽內(nèi)的腳本不會執(zhí)行),加了這兩個屬性其中一個那么腳本文件會異步加載執(zhí)行。
首先檢查defer在瀏覽器中執(zhí)行順序(檢查瀏覽器為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內(nèi)嵌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("內(nèi)嵌js")
</script>
</body>
</html>
在chome,firfox的控制臺中,輸出先后順序為
head內(nèi)嵌js
img
內(nèi)嵌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.
轉(zhuǎn)載于:https://www.cnblogs.com/outside/p/3723722.html
總結(jié)
以上是生活随笔為你收集整理的defer与async的认识的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ES权威指南[官方文档学习笔记]-8
- 下一篇: selenium+ant+testng测