最近注意到,站点强制HTTPS后在Chrome下老是报警告,排除了不少http导致的跨域提醒,然后又出现了document.write报错警告,包括cnzz统计,百度收录,分享等都有该问题,于是想办法解决了一下。
该警告是这样的:文章源自IT老刘-https://wp.itlao6.com/3191.html
“A parser-blocking,cross site (i.e. different eTLD+1) script, https://s22.cnzz.com/z_stat.php?id=XXXX.js,is invoked via document.write. The network request for this script MAY beblocked by the browser in this or a future page load due to poor network connectivity.”文章源自IT老刘-https://wp.itlao6.com/3191.html
Chrome之所以出现该警告,主要是从加载速度上考虑的,特别是在2g情况下,Chrome会直接忽略document.wirte的加载;基于这一原因,我们可以想到解决办法,改为异步加载:文章源自IT老刘-https://wp.itlao6.com/3191.html
// 将代码中的xxxxxxx替换成你的id即可 <span id='cnzz_stat_icon_xxxxxxx'></span> <script> var cnzz_s_tag =document.createElement('script'); cnzz_s_tag.type ='text/javascript'; cnzz_s_tag.async =true; cnzz_s_tag.charset= 'utf-8'; cnzz_s_tag.src ='https://s96.cnzz.com/z_stat.php?id=xxxxxxx&show=pic'; var root_scnzz =document.getElementsByTagName('script')[0]; root_scnzz.parentNode.insertBefore(cnzz_s_tag,root_scnzz); </script>
同理,百度hm代码也可以修改:文章源自IT老刘-https://wp.itlao6.com/3191.html
// 下面代码中xxxxxxx改为你的id <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?xxxxxxx"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
个人博客: IT老五 简书:ThinkinLiu文章源自IT老刘-https://wp.itlao6.com/3191.html
源创不易,允许转载,来源勿删,多谢合作文章源自IT老刘-https://wp.itlao6.com/3191.html
文章源自IT老刘-https://wp.itlao6.com/3191.html 文章源自IT老刘-https://wp.itlao6.com/3191.html
评论