A Parser-blocking, cross-origin script is invoked via document.write - how to circumvent it?

JavascriptGoogle Chromedocument.write

Javascript Problem Overview


Google Chrome started implementing Blocking the load of cross-origin, parser-blocking scripts inserted via document.write in the main frame on slow networks, which causes the following error:

> A Parser-blocking, cross-origin script, http://example.org/script.js, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity.

However, my web page requires loading a third party script synchronously, using document.write('<script src="..."></script>'). How to circumvent that blockade?

More about that change:

Javascript Solutions


Solution 1 - Javascript

According to Google Developers article, you can:

Solution 2 - Javascript

@niutech I was having the similar issue which is caused by Rocket Loader Module by Cloudflare. Just disable it for the website and it will sort out all your related issues.

Solution 3 - Javascript

Don't use document.write, here is workaround:

var script = document.createElement('script');  
script.src = "....";  
document.head.appendChild(script);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionniutechView Question on Stackoverflow
Solution 1 - JavascriptniutechView Answer on Stackoverflow
Solution 2 - JavascriptVaibhav MistryView Answer on Stackoverflow
Solution 3 - JavascriptGrayView Answer on Stackoverflow