Skip to content

Instantly share code, notes, and snippets.

@mutongwu
Last active November 15, 2022 02:57
Show Gist options
  • Save mutongwu/953a472fd1768fe27c580108f853e1b6 to your computer and use it in GitHub Desktop.
Save mutongwu/953a472fd1768fe27c580108f853e1b6 to your computer and use it in GitHub Desktop.

Async vs defer

1. 相同点:都能够异步并行加载,不阻塞dom和其它资源的加载。
2. 不同点:
    1. 不同的Async script,加载与执行没有顺序,谁先回来先执行,且跟 DomContentLoaded 事件无关(可能在它触发之前或之后)
    2.  defer 的script有顺序,在前面的先执行。代码执行完成后,才会触发 DomContentLoaded 事件。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment