async:异步加载脚本,下载完成后立即执行,执行顺序不确定defer:异步加载脚本,在文档解析完成后按顺序执行 1. async特性: - 脚本加载并行于HTML解析 - 下载完成后立即暂停HTML解析并执行脚本 - 多个async脚本执行顺序不可预测 - 适用于不依赖DOM的独立第三方脚本2. defer特性: - 脚本加载同步于HTML解析 - 等到
The scripts marked withdeferare executed right after the domInteractive event, which happens after the HTML is loaded, parsed and the DOM is mounted. Once this is done, the browser will emit the domComplete event, and then onLoad. Async and defer are basically two boolean attribut...