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

血红的双手。 提交于 2019-11-27 09:28:12

问题


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:

  • Design document
  • Longer document
  • Web Incubator CG issue
  • Chrome Issue

回答1:


According to Google Developers article, you can:

  • Use asynchronous script loading, using <script src="..." async> or element.appendChild(),
  • Submit the script provider to Google for whitelisting.



回答2:


@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.




回答3:


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

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


来源:https://stackoverflow.com/questions/39610829/a-parser-blocking-cross-origin-script-is-invoked-via-document-write-how-to-ci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!