延迟加载使用 document.write 的双击广告的最佳方法是什么?
通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
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
好的,基本上有两种主要方式将广告呈现到屏幕上。
老实说,Javascript 通常只渲染一个 iFrame。广告网络希望 iFrame b/c 能够让他们轻松删除 cookie(该用户是否在网络上的其他地方看到过此广告),并且很容易删除展示像素(计数方法该页面已呈现)。
所以这是你最好的选择。
iframe.src = 'myurl?'; iframe.reload();
这应该就是您需要做的全部事情。将其设置为加载其他所有内容,然后最后加载广告 iFrame。
请注意,这可能会影响您的广告收入。这取决于用户体验,但如果广告在用户将其滚动出屏幕后才加载,那么您将无法获得点击或赚钱。
另外,请密切关注广告网络的表现。我知道这些人有相当好的响应时间,但是有很多广告网络,有时甚至是大公司响应时间很差。
OK, so there are basically two primary ways in which an ad is rendered to the screen.
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.
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.
我会给你另一个不使用 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()
我习惯于在页面底部的隐藏 div 中呈现广告,并使用 javascript 移动它们。
类似这样的内容,无论您想在哪里放置广告:
以及在页面末尾:
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:
and at the end of the page:
除非您投放富媒体广告,否则 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.
因此,似乎有一个围绕此形成的标准,称为友好 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.
我用 iframe 解决了这个问题。我用 iframe 替换了 script 标签,该 iframe 指向我的服务器上包含 script 标签的简单页面。
adpage.htm替换了标签
我用
,其中仅包含:
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
with
adpage.htm simply contains:
您是说使用 Document.write 延迟加载广告吗
那么这是最好的方法
将惰性加载器添加到 Head
在 LazyHTML 包装器中使用 Document.write 包装广告
更多信息: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
More info: LazyHTML Github