載入JavaScript code的最佳時機

 To summarize:

async and defer both instruct the browser to download the script(s) in a separate thread, while the rest of the page (the DOM, etc.) is downloading, so the page loading is not blocked by the scripts.

If your scripts should be run immediately and they don't have any dependencies, then use async.

If your scripts need to wait for parsing and depend on other scripts and/or the DOM being in place, load them using defer and put their corresponding <script> elements in the order you want the browser to execute them.

留言

這個網誌中的熱門文章

溪和食品有限公司 - 觀光工廠接待人員(薪約30K.免費供餐),今天投遞此份工作。