document.write causing blank page

Recently my company website has a 3rd-party site traffic tracking code blocking the site from rendering. The download of that JavaScript file never end until gateway timeout, hindering the site from complete loading.

I tried to make the JavaScript to be downloaded async so as to avoid the blocking issue, sadly it turns out a blank page.

Drill down to the root clause of the blank page issue, I find that it is caused by a document.write statement in the downloaded code. And find out that: document.write can only be used for inline,when the code is downloaded async, document.write will simply create a blank document and write the content on it.

To avoid it, we need to overwrite the document.write function to fit with the change. Detail can be found from the site:
https://github.com/eligrey/async-document-write

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Answer * Time limit is exhausted. Please reload CAPTCHA.