延迟加载使用 document.write 的双击广告的最佳方法是什么?

发布于 2024-10-09 21:37:03 字数 451 浏览 3 评论 0原文

通过 doubleclick 请求的广告通常由广告提供商网络提供服务,该网络返回 javascript,进而执行 document.write 以将广告放置在页面中。使用 document.write 要求文档处于打开状态,这意味着页面尚未达到 document.complete。这会妨碍延迟或延迟加载广告内容。将此类代码放在页面底部很有帮助,但不足以减少最重要的“页面加载”时间。 “友好的 iframe”是我们拥有的最好的吗?是否有其他替代方案,例如重写 document.write 的巧妙方法,以保留 dom 中的正确位置?

第三方广告使用 document.write 将脚本和内容添加到页面的“当前”位置。页面所有者无法控制广告脚本,也无法指定显示目标 div。广告脚本期望在调用它的文档位置写入和呈现,因此如何使用延迟动态脚本加载正确定位广告并不明显。将脚本延迟加载到上下文中很简单,但通过 document.write 呈现的第三方内容并不那么容易实现。

Ads requested via doubleclick often get served from an ad provider network that returns javascript that in turn performs document.write to place ads in the page. The use of document.write requires that the document be open, implying that the page hasn't reached document.complete. This gets in the way of deferring or lazy loading ad content. Putting such code at page bottom is helpful but doesn't do enough to lower all-important "page-loaded" time. Are "friendly iframes" the best we have? Is there any other alternative such as a clever way to override document.write that preserves the proper place in the dom?

Third party ads use document.write to add script and content into the "current" location in a page. The page owner doesn't have control over ad scripts and can't specify a display target div. The ad script expects to write and render at the document position where it is called, so it's not obvious how to position the ad correctly using deferred dynamic script loading. Lazy loading script into context is straightforward, but third-party content rendered in place via document.write is not so easily achieved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

暖伴 2024-10-16 21:37:03

postscribe.js 由 krux 开发,如 HTML5 开发会议上所示。

http://krux.github.com/postscribe/doc/postscribe.html
https://npmjs.org/package/postscribe

postscribe.js by krux, as demonstrated at the HTML5 Dev Conference.

http://krux.github.com/postscribe/doc/postscribe.html
https://npmjs.org/package/postscribe

冷夜 2024-10-16 21:37:03

好的,基本上有两种主要方式将广告呈现到屏幕上。

  1. 使用 Javascript include 和一些变量。
  2. 使用您放置在页面上的 iFrame。

老实说,Javascript 通常只渲染一个 iFrame。广告网络希望 iFrame b/c 能够让他们轻松删除 cookie(该用户是否在网络上的其他地方看到过此广告),并且很容易删除展示像素(计数方法该页面已呈现)。

所以这是你最好的选择。

  1. 找出正在呈现的 iFrame URL。如果你好意地询问,有些网络会直接告诉你。
  2. 将 iFrame 放置在画布/html 上并具有适当的尺寸(例如 728x90),但将其指向您域中的已知空白 URL。 (或者具有与您的页面相匹配的背景颜色)。
  3. 添加在适当的时间更新 iFrame 的 SRC 的 javascript。

iframe.src = 'myurl?'; iframe.reload();

这应该就是您需要做的全部事情。将其设置为加载其他所有内容,然后最后加载广告 iFrame。

请注意,这可能会影响您的广告收入。这取决于用户体验,但如果广告在用户将其滚动出屏幕后才加载,那么您将无法获得点击或赚钱。

另外,请密切关注广告网络的表现。我知道这些人有相当好的响应时间,但是有很多广告网络,有时甚至是大公司响应时间很差。

OK, so there are basically two primary ways in which an ad is rendered to the screen.

  1. Using a Javascript include and some variables.
  2. Using an iFrame that you place on the page.

And honestly, the Javascript normally just renders an iFrame. Ad Networks want the iFrame b/c it gives them the easy ability to drop cookies (has this user seen this ad elsewhere on the network) and it's easy to drop impression pixels (method of counting that page was rendered).

So here's your best bet.

  1. Figure out the iFrame URL that is being rendered. Some networks will tell it to you directly if you ask nicely.
  2. Place the iFrame on your canvas / html with the appropriate size (e.g. 728x90), but point it to a known URL on your domain that is blank. (or has a background color that matches your page).
  3. Add the javascript that updates the SRC of the iFrame at the appropriate time.

iframe.src = 'myurl?'; iframe.reload();

That should be all that you need to do. Set it up so that everything else loads and then load the advertising iFrames last.

Note that this may affect your revenue from the ads. It depends on the user experience, but if the ads don't load until the user has scrolled them off the screen, then you won't get clicks or make money.

Also, keep an eye on ad network performance. I know that these guys have pretty good response times, but there are lots of ad networks and sometimes even the big guys have crappy response times.

雨巷深深 2024-10-16 21:37:03

我会给你另一个不使用 iframe 的解决方案。请参阅 http://github.com/shenjunru/LazyWrite

它将帮助您推迟 document.write ()

I will give you another solution without using iframe. See http://github.com/shenjunru/LazyWrite

It will help you to defer the document.write()

寻找一个思念的角度 2024-10-16 21:37:03

我习惯于在页面底部的隐藏 div 中呈现广告,并使用 javascript 移动它们。

类似这样的内容,无论您想在哪里放置广告:

<div id="destid" style="width:350px; heigh: 200px"></div>

以及在页面末尾:

<div style="display:none">   
    <script type="text/javascript"> 
    document.write("<div id='srcid'>");
    //your doubleclickcode
    document.write("</div>");
    </script>
<script type="text/javascript"> 
    $("#srcid").appendTo("#destid");
</script>
</div>

I get used to render the ads at the bottom of the page in a hidden div and moving them with javascript.

something like this wherever you want to put your ads:

<div id="destid" style="width:350px; heigh: 200px"></div>

and at the end of the page:

<div style="display:none">   
    <script type="text/javascript"> 
    document.write("<div id='srcid'>");
    //your doubleclickcode
    document.write("</div>");
    </script>
<script type="text/javascript"> 
    $("#srcid").appendTo("#destid");
</script>
</div>
输什么也不输骨气 2024-10-16 21:37:03

除非您投放富媒体广告,否则 iframe 方法将正常工作。这些广告类型通常基于 Flash,并且在某些情况下会扩展到其容器之外。如果您使用 iframe,富媒体广告将仅限于容器 (iframe)。

容纳所有可能的广告的最佳方法是使用脚本方法。

The iframe method will work fine unless you are serving rich media ads. These are the type of ads that are generally flash based and, in some cases, expand out of their container. If you use iframes the rich media ads are restricted to the container (iframe).

The best way to accommodated all possible ads is to use the script method.

你与昨日 2024-10-16 21:37:03

因此,似乎有一个围绕此形成的标准,称为友好 iframe (FIF)。这感觉有点像黑客攻击,但我感觉 IAB 是幕后黑手,这让我感觉好多了。

以下是 IAB 的文档: http://www.iab.net/media/file/ rich_media_ajax_best_practices.pdf

它对我有用,即使您将 js 动态写入 iframe,它仍然允许富媒体广告扩展到其空间之外。

So there seems to be a standard forming around this called friendly iframes (FIF). It feels a bit like a hack but I feel better that the IAB is behind it.

Here's the documentation from the IAB: http://www.iab.net/media/file/rich_media_ajax_best_practices.pdf

It worked for me, and even though you are writing the js dynamically into an iframe, it still allowed the rich media ads to expand outside their space.

墟烟 2024-10-16 21:37:03

我用 iframe 解决了这个问题。我用 iframe 替换了 script 标签,该 iframe 指向我的服务器上包含 script 标签的简单页面。

adpage.htm替换了标签

<script src="ad provider's url containing document.write()" type="text/javascript">
</script>

我用

<iframe src="adpage.htm" style="border:none;width:...height:..."></iframe>

,其中仅包含:

<html><head></head>
<body style="margin:0px;">
<script src="ad provider's url containing document.write()" type="text/javascript">
</script>
</body></html>

I solved the problem with an iframe. I replaced the script tag with an iframe that points to a simple page on my server that contains the script tag.

I replaced the tag

<script src="ad provider's url containing document.write()" type="text/javascript">
</script>

with

<iframe src="adpage.htm" style="border:none;width:...height:..."></iframe>

adpage.htm simply contains:

<html><head></head>
<body style="margin:0px;">
<script src="ad provider's url containing document.write()" type="text/javascript">
</script>
</body></html>
任谁 2024-10-16 21:37:03

您是说使用 Document.write 延迟加载广告吗
那么这是最好的方法
将惰性加载器添加到 Head

在 LazyHTML 包装器中使用 Document.write 包装广告

<div class="lazyhtml" data-lazyhtml>
  <script type="text/lazyhtml">
  <!--
  
Your Adcode with Document.write  (including wrapping <script>,<style> tags)
  
  -->
  </script>
</div>

更多信息:LazyHTML Github

Did you mean Lazy load ads with Document.write
Then This is the best way
Add the Lazy loader to Head

Wrap the Ad with Document.write in LazyHTML Wrapper

<div class="lazyhtml" data-lazyhtml>
  <script type="text/lazyhtml">
  <!--
  
Your Adcode with Document.write  (including wrapping <script>,<style> tags)
  
  -->
  </script>
</div>

More info: LazyHTML Github

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文