document.write (DW):
Why It Is Used:
-
It is the most reliable way for the content (Widget or Ad) to “know” where the HTML author intends for it to be placed.
-
Scripts can have a negative impact on page performance and modern browsers have taken to blocking scripts. DW can be used to inject and bypass these blocks.
-
It works everywhere, all the time
Why It Shouldn’t Be Used:
-
Serializes the rendering engine to pause until external script is loaded. This could take much longer to load than an internal (none-DW) script.
-
Browser must download, parse, and execute the first external JavaScript resource before it executes the document.write() that fetches the additional external resources.
-
No single script should have the right to control (alter) a page before it’s ready to be viewed
Common Examples:
-
Twitter Stream
-
Google Analytics
What We Could Do To Improve User Experience with Tag Auditor:
What Authors Can Do To Minimize The Use of document.write