19788 shaares
136 private links
136 private links
In yesterday’s blog post, Making the HTTP Archive faster, one of the biggest speedups came from not using a script loader. It turns out that script loader was using document.write to load scripts dynamically. I wrote about the document.write technique in Loading Script Without Blocking back in April 2009, as well as in Even Faster Web Sites (chapter 4). It looks something like this:
document.write('<script src="' + src + '" type="text/javascript"><\/script>'):
The problem with document.write for script loading is:
Every DOM element below the inserted script is blocked from rendering until the script is done downloading (example).
It blocks other dynamic scripts (example). One exception is if multiple scripts are inserted using document.write within the same SCRIPT block (example).