Script Tag - async & defer

前端 未结 8 1668
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 13:52

I have a couple of questions about the attributes async & defer for the

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:59

    HTML5: async, defer

    In HTML5, you can tell browser when to run your JavaScript code. There are 3 possibilities:

    
    
    
    
    
    
    1. Without async or defer, browser will run your script immediately, before rendering the elements that's below your script tag.

    2. With async (asynchronous), browser will continue to load the HTML page and render it while the browser load and execute the script at the same time.

    3. With defer, browser will run your script when the page finished parsing. (not necessary finishing downloading all image files. This is good.)

提交回复
热议问题