有没有办法在javascript代码中缓存Google广告?

时间:2019-05-14 14:33:03

标签: caching adsense cache-control ttl google-advertising-id

我正在媒体网页上工作。它具有一个弹出窗口,其中显示几行动态内容,并具有用于呈现广告的广告位。但是广告在弹出窗口中的加载速度很慢(> 1秒)。有没有一种方法可以在加载的父媒体网页上缓存广告。

在媒体网页上,我将脚本包含为第三方脚本。单击任何关键字后,在此父媒体网页中,它将显示一个弹出窗口,其中包含一些信息和广告。在此弹出窗口中,需要花费更多时间来加载广告。

请检查以下有关Google广告的示例代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
  <style>
  body {font-family: Arial, Helvetica, sans-serif;}
        .modal {
          display: none; 
          position: fixed; 
          z-index: 1; 
          padding-top: 100px; 
          left: 0;
          top: 0;
          width: 100%; 
          height: 100%; 
          overflow: auto; 
          background-color: rgb(0,0,0); 
          background-color: rgba(0,0,0,0.4); 
        }
        .modal-content {
          background-color: #fefefe;
          margin: auto;
          padding: 20px;
          border: 1px solid #888;
          width: 80%;
        }
        .close {
          color: #aaaaaa;
          float: right;
          font-size: 28px;
          font-weight: bold;
        }

        .close:hover,
        .close:focus {
          color: #000;
          text-decoration: none;
          cursor: pointer;
        }
  </style>
    <script async="async" src="https://www.googletagservices.com/tag/js/gpt.js"></script>
    <script>
      var googletag = googletag || {};
      googletag.cmd = googletag.cmd || [];
    </script>
  <script>
    googletag.cmd.push(function() {
      googletag.defineSlot('/134312942/COS_HINDSIGHT_300x250', [[300, 100], [300, 250]], 'div-gpt-ad-1556193480814-0')
      .addService(googletag.pubads())
      googletag.pubads().enableSingleRequest();
      googletag.enableServices();
    });
  </script>
</head>
<body>
<button id="myBtn">Open Modal</button>
<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close">&times;</span>
    <div id='div-gpt-ad-1556193480814-0'>
        <script>
          googletag.cmd.push(function() { 
            googletag.display('div-gpt-ad-1556193480814-0'); 
          });
        </script>
      </div>
  </div>
</div>
<script>
var modal = document.getElementById("myModal");
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
  modal.style.display = "block";
}
span.onclick = function() {
  modal.style.display = "none";
}
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
</script>
</body>
</html>

多个广告应缓存并快速加载(最好少于500毫秒)。

0 个答案:

没有答案