Using DOMContentReady considered anti-pattern by Google

后端 未结 7 2263
广开言路
广开言路 2020-12-08 05:20

A Google Closure library team member asserts that waiting for DOMContentReady event is a bad practice.

The short story is that we don\'t want to wai

7条回答
  •  臣服心动
    2020-12-08 05:44

    One reason to avoid inline scripts is that it requires you place any dependency libraries before them in the document, which will probably negate the performance gains of inline scripts. The best practice I'm familiar with is to place all scripts (in a single HTTP request!) at the very end of the document, just before . This is because script-loading blocks the current request and all sub-requests until the script is completely loaded, parsed, and executed.

    Short of a magic wand, we'll always have to make these trade-offs. Thankfully, the HTML document itself is increasingly going to become the least resource-intensive request made (unless you're doing silly stuff like huge data: URLs and huge inline SVG documents). To me, the trade-off of waiting for the end of the HTML document seems the most obvious choice.

提交回复
热议问题