[removed] vs script defer

前端 未结 1 515
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-07 15:45

Here it\'s said, that there are 4 readyState possible values for html documents:

uninitialized - Has not started loading yet
loading

1条回答
  •  生来不讨喜
    2021-02-07 16:18

    Read on to http://www.w3.org/html/wg/drafts/html/master/scripting-1.html#attr-script-defer:

    There are three possible modes that can be selected using these attributes. If the async attribute is present, then the script will be executed asynchronously, as soon as it is available. If the async attribute is not present but the defer attribute is present, then the script is executed when the page has finished parsing. If neither attribute is present, then the script is fetched and executed immediately, before the user agent continues parsing the page.

    http://www.w3.org/TR/html5/syntax.html#the-end tells you that deferred scripts run first:


    Execute the first script in the list of scripts that will execute when the document has finished parsing.

    Then the DOMContentLoaded event:

    Queue a task to fire a simple event that bubbles named DOMContentLoaded at the Document.

    load events fire after both of these, always.

    0 讨论(0)
提交回复
热议问题