PageSpeed: Avoid document.write (deprecated)
Overview
Using document.write() to fetch external resources, especially early in the document, can significantly increase the time it takes to display a web page.
How does your site score on this recommendation?
Details from Google
Modern browsers use speculative parsers to more efficiently discover external resources referenced in HTML markup. These speculative parsers help to reduce the time it takes to load a web page. Since speculative parsers are fast and lightweight, they do not execute JavaScript. Thus, using JavaScript's document.write() to fetch external resources makes it impossible for the speculative parser to discover those resources, which can delay the download, parsing, and rendering of those resources.
Using document.write() from external JavaScript resources is especially expensive, since it serializes the downloads of the external resources. The browser must download, parse, and execute the first external JavaScript resource before it executes the document.write() that fetches the additional external resources. For instance, if external JavaScript resource first.js
contains the following content:
document.write('<script src="second.js"><\/script>');
The download of first.js and second.js will be serialized in all browsers. Using one of the recommended techniques described in the sidebar can reduce blocking and serialization of these resources, which in turn reduces the time it takes to display the page.
Read our Lighthouse documentation to learn more on avoiding document.write().