【问题标题】:Google Adsense loads scripts multiple timesGoogle Adsense 多次加载脚本
【发布时间】:2015-06-13 12:11:42
【问题描述】:

我有一个显示 Google Ads 的页面 - 其中三个。广告初始化如下:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<ins class="adsbygoogle class-resp" style="display:inline-block" data-ad-client="ca-pub-4283524395367264" data-ad-slot="8923673879"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

<ins class="adsbygoogle class-resp" style="display:inline-block" data-ad-client="ca-pub-4283524395367264" data-ad-slot="8923673879"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

<ins class="adsbygoogle class-resp" style="display:inline-block" data-ad-client="ca-pub-4283524395367264" data-ad-slot="8923673879"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

问题在于页面大小大得离谱,原因主要是每个广告似乎都需要自己下载以下每个脚本,即每个脚本都下载了 3 次,每次页面加载增加了大约 700kb (这对于移动浏览来说太大了)

http://pagead2.googlesyndication.com/pagead/js/r20150402/r20150224/show_ads_impl.js http://pagead2.googlesyndication.com/pagead/js/r20150402/r20150224/expansion_embed.js http://pagead2.googlesyndication.com/pagead/js/r20150402/r20110914/abg.js

有没有人知道强制三个广告共享上述三个脚本的单个下载的方法,或者每个广告都必须下载各自的副本??

【问题讨论】:

    标签: javascript adsense google-ads-api


    【解决方案1】:

    一旦下载了脚本,它就会被缓存(如果缓存头可用),因为脚本的第二个请求是从缓存中加载的,所以它不会浪费任何带宽或不会向域/主机发送任何请求。

    我刚刚查了http://pagead2.googlesyndication.com/pagead/js/r20150402/r20150224/show_ads_impl.js

    HTTP/1.0 200 OK =>
    P3P => policyref="http://www.googleadservices.com/pagead/p3p.xml", CP="NOI DEV PSA PSD IVA IVD OTP OUR OTR IND OTC"
    Timing-Allow-Origin => *
    Cross-Origin-Resource-Policy => cross-origin
    Vary => Accept-Encoding
    Date => Sat, 04 Sep 2021 06:08:13 GMT
    Expires => Sat, 04 Sep 2021 06:08:13 GMT
    Cache-Control => private, max-age=1209600
    Content-Type => text/javascript; charset=ISO-8859-1
    X-Content-Type-Options => nosniff
    Content-Disposition => attachment; filename="f.txt"
    Server => cafe
    X-XSS-Protection => 0
    Accept-Ranges => none
    

    它有缓存控制头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      • 2014-01-22
      • 2015-07-08
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 2018-01-16
      相关资源
      最近更新 更多