0

是否有任何简单的解决方案可以并行运行第三方 javascript-tags?

只是一个 html 页面上的几个脚本,它不会一个接一个地加载/我知道对于广告它使用像 doubleclick 这样的广告服务器工作,但这不是必需的,它不仅是广告,有些需要保持能够分析 html 内容用户代理、IP、引荐来源网址或更多

示例, 您可能非常了解

1.

<script src="http://another-ad-service.com/get-js.aspx?&cwadformat=728*90"</script>

2.

<script language="JavaScript" type="text/javascript">
var 1a_account   = '12345';
var 1a_zonesize  = '12345-5';
var 1a_adtype    = 'js';
</script>
<script type="text/javascript" src="http://agency1a.somewhere/12345.js"></script>

3.

<script type='text/javascript'>
<!--//<![CDATA[
   document.MAX_ct0 ='';
   var m3_u = (location.protocol=='https:'?'https://an-advertisment-agency.honolulu...'
   var m3_r = Math.floor(Math.random()*99999999999);
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("zoneid=12345");document.write("&amp;nodis=1");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : 
   (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if ((typeof(document.MAX_ct0) != 'undefined') && 
   (document.MAX_ct0.substring(0,4) == 'http')) {
       document.write ("&amp;ct0=" + escape(document.MAX_ct0));
   }
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'></scr"+"ipt>");
//]]>--></script>

4.

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12345-2']);
  _gaq.push(['_setDomainName', 'website.edu']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ?
    'https://ssl' : 'http://www') + '.gooooogle-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
<script type="text/javascript"> window.google_analytics_uacct = "UA-12345-2"; </script>
4

1 回答 1

1

加载外部 JavaScript 文件时,您可以将async属性添加到脚本标签。

<script src="http://another-ad-service.com/get-js.aspx?&cwadformat=728*90" async></script>

不过,该脚本需要是自给自足的,并且不依赖于您在该脚本之前加载的其他代码。

于 2012-12-03T14:12:27.610 回答