假設我有這樣的HTML內容:我們可以設置JavaScript以異步加載JavaScript嗎?
<html>
<head>
<script src="myscript1.js"></script>
<script src="myscript2.js"></script>
<script src="myscript3.js"></script>
<script src="myscript4.js"></script>
<script src="jquery.js"></script>
</head>
<body>
<!--- CONTENT --->
...
.
.
.
.
.
<!--- CONTENT --->
</body>
</html>
我可以這樣做:
<html>
<head>
<script src="myscript1.js"></script>
<script src="myscript2.js"></script>
<script src="myscript3.js"></script>
<script src="myscript4.js"></script>
<script src="jquery.js"></script>
<script>
$(function() {
$("script").attr("async","async");
});
</script>
</head>
<body>
<!--- CONTENT --->
...
.
.
.
.
.
<!--- CONTENT --->
</body>
</html>
是不是有效?並會實際上異步加載JavaScript或不? :)
感謝您的時間...!
.............................................. .......................................
你爲什麼不試試? – Ian