记录生活 学习SEO优化 | 他日若遂凌云志 敢笑黄巢不丈夫
>>Home > 学习笔记 > 广告和网页同时异步加载功能

广告和网页同时异步加载功能

Tags: | | 作者:海天无影

海天的两个网站,博客和电影站都已经投放了百度联盟和Google Adsense(以下简称GA)的广告,而每个网站的都是GA的广告数量多一点,不为别的,只因为GA的价钱高一点,虽然GA点一次也就才很少的几分钱,但可是美元。而百度既然申请下来了,不放的话有点不好意思,所以就象征性的每个网站摆了一个百度的广告。

虽然现在GA的价钱比百度高一点,GA的时间也不百度老,但海天发现百度联盟广功能的确很强大,很照顾站长。就比如这次说的百度联盟广告和网页同时异步加载功能。

百度联盟广告最近新推出了一个很实用的功能,广告和网页内容同时异步加载功能,这个功能就能够解决因为广告而影响网页的加载速度。

网页的加载原理,是从一个页面从头到尾一步步执行来的,如果你的广告JS代码,放在网页中,那么执行下来到广告的时候,必须先运行加载完广告,然后再接着处理下面的网页内容,这样是很影响网页加载速度的。

海天原来也弄过这样一个方法来解决因为广告影响网页加载速度的问题,就是加载完页面后再加载广告的JS代码。这个问题的确可以很好的解决因为广告而引起的网页加载速度慢,但是这样做也有一个稍稍的不好之处,就是现在很多站长因为要优化网页速度,将页面需要调用的JS代码都一起放在网页的最后来加载,再加上现在广告业是网页最后加载,就造成了最后突然要加载很多JS代码,会使网页打开,稍微卡那么一小下。

现在百度广告管家提供了Iframe代码广告位置的投放,因为Iframe的执行机制是异步加载,所以广告和网页内容的加载不会受到相互影响。下面就来看看代码:

1、创建并上传proxy.html文件到你的网站。proxy.html的内容如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="margin:0">
<script type="text/javascript" src="http://cbjs.baidu.com/js/s.js"></script>
<script type="text/javascript">
<!-- 读取url中的参数“id”并绘制广告 -->
(function() {
var match = location.href.match(/(\?|&)id=([^&]+)(&|$)/);
if (match) {
var slotId = parseInt(match[2], 10);
if (slotId) {
BAIDU_CLB_singleFillSlot(match[2]);
}
}
})();
</script>
</body>
</html>
注:文件用于读取Iframe标签里的src传递过来的广告位id,然后调用百度广告管家系统的函数,最后将对应的具体广告内容加载。

2、开始在网页中投放iframe广告代码

1) 在百度广告管家的管理系统中查看广告位的id、宽度和高度信息,如下图所示:

百度广告管家投放iframe广告

百度广告管家投放iframe广告,选择广告位

2)得到上面的参数后, 参照以下规范写出iframe代码,然后将代码放到网页需要加载广告相应的位置。iframe广告代码如下:

<iframe src="proxy.html?id=44049" width="728" height="60" scrolling="no" frameborder="0" style=”display:block;margin:0”></iframe>
注:其中,src属性的取值由proxy.html文件的有效路径加上“?id=广告位id”组成;而width和height的值分别是广告位的宽度和高度。两处所需取值分别对应上一步图片中看到的广告位id、宽度和高度。

虽然这个方法用起来还是有点麻烦,广告改动的时候,还需要在百度广告管家中修改iframe代码,但是不得不说这个方法的确很好的解决了网页加载速度的问题。而且看文章的调用方法,其他广告比如GA,一样可以用百度广告管家管理来实现这个广告和网页内容同时异步加载的功能。

百度广告管家,对于广告的管理和投放真的做的很不错,除了上面这个广告和网页内同容时异步加载的实用功能以外。还有对“一个人一天只弹出一次广告”、“针对不同网络供应商、地域显示不同广告”等其他很不错的广告管理和投放功能。大家没事可以试试百度广告管家哦~

日志信息 »

该日志于2010-08-24 08:00由 海天无影 发表在学习笔记分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下转载到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

28条评论▼点击进行评论


  1. Warning: copy(/home/wwwroot/haitian/blog/avatar/80c6778d63af710963c2c43c81bbe833.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    刚刚放了广告 没有做进一步的研究


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      这个不是百度联盟的广告
      是百度管家 可以帮你管理广告的 不只是百度的广告~


  2. Warning: copy(/home/wwwroot/haitian/blog/avatar/0dcedda7123567217b5ce259e203a209.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    给百度做广告啦,呵呵


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 只是觉得 百度管家这个服务 做的不错~


  3. Warning: copy(/home/wwwroot/haitian/blog/avatar/d94967b298c3fcfed3f8e5a6c5181f42.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我都放了,嘿嘿,


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 这个是百度管家啦
      不是百度广告~


  4. Warning: copy(/home/wwwroot/haitian/blog/avatar/67ba286d63f39ec5a615c1404cb98d94.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    杯具啊。我的广告都给K完了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 那么悲剧?难道被人恶意点击?


  5. Warning: copy(/home/wwwroot/haitian/blog/avatar/b2986defdd28dcaa196e317a94d82e31.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    一个人一天只弹出一次广告…..百度联盟还有弹窗广告?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 这个是百度广告管家 帮你管理网站的广告的 不单是百度联盟的广告


  6. Warning: copy(/home/wwwroot/haitian/blog/avatar/12b9ca311887d0c56ef18c36e8dd5fbd.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    百度真赚不了几毛钱


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      是啊 我这个说的是百度管家 不是广告 呵呵~


  7. Warning: copy(/home/wwwroot/haitian/blog/avatar/5e29ff2eb17b2447c034c302eff3a6e1.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    GA的账号,我几个月没登陆了,不知道里面有几毛钱


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      GA 我这几天也没看了 先不管了
      反正不可能一下子到100的 呵呵


  8. Warning: copy(/home/wwwroot/haitian/blog/avatar/670e5c397e4e6b6450e0b8b0209de528.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我还是先申请下来再说吧~~悲剧~~


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      百度联盟貌似还比较容易申请的啊
      我说的这个是百度的广告管家 不是广告呵呵


  9. Warning: copy(/home/wwwroot/haitian/blog/avatar/a12eb4e39ba543feb9ff6a105090b952.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复


    网赚对博客来说太难了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 说的是啊
      带着玩吧~


  10. Warning: copy(/home/wwwroot/haitian/blog/avatar/3a6d76790a7f616507cedd378f3cabd4.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    其实吧,我不爱看你的博客,因为你写的太好了,我嫉妒,哼哼


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      ;-) 额 这个 我写的可没那么好~


  11. Warning: copy(/home/wwwroot/haitian/blog/avatar/e657612476777faf50d5f28627975291.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    百度的价钱太低了,没动力做。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 话说 这个不是百度联盟广告
      是百度广告管家 不一定只能放百度的广告哦~


  12. Warning: copy(/home/wwwroot/haitian/blog/avatar/d53e3eb8cf43fc1b9101ae2c247319a1.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    当初不珍惜,谷歌把我的GA搞封了。

    百度的又不想做。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 GA被封了啊 那很悲剧的啊~


  13. Warning: copy(/home/wwwroot/haitian/blog/avatar/11c106aa2b44bb82bc316048b996ecd2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    广告的代码能随便改的吗?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      恩 这个是百度广告管家 你可以随便放什么广告 不一定非要是百度的


  14. Warning: copy(/home/wwwroot/haitian/blog/avatar/0c9157a4f48ba4cc94ada5e7016bcf72.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    你不是以前发过一次的吗?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      哦 上次那个是先加载文章再来广告 等加载广告的时候 还是会小卡一下
      这次的这是两个同时加载又不互相影响的


  15. Warning: copy(/home/wwwroot/haitian/blog/avatar/f8399cd22a875649cb30f4a98892113f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    还没挂百度的呢……


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 这个是百度广告管家的服务~


  16. Warning: copy(/home/wwwroot/haitian/blog/avatar/79a9e817c5e3dfd97ce5bda425a1450f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    百度还真会为我们着想啊……


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 是啊 这个服务还是不错的~


  17. Warning: copy(/home/wwwroot/haitian/blog/avatar/c4668a51a1479f6c344c7b79636c2236.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    你都用上百度管家了我都没用


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 说实话 我也没用……
      只是看到邮件 感觉很不错的服务
      我还是用上次那个先加载文章再加载广告的~


  18. Warning: copy(/home/wwwroot/haitian/blog/avatar/ff042d9f1716c89d0620f4880c1c0925.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    有时间研究一下,我基本上是挂在那里不管它。帮你点点。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 感谢啊 好久没上网了 去你那看看~


  19. Warning: copy(/home/wwwroot/haitian/blog/avatar/bf12d703481f992fb051334a04f27c7b.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    就放一个百度广告,其实也没有比较弄的这么麻烦,页面广告多的话,倒是可以试试。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 只是这个服务的确很不错~


  20. Warning: copy(/home/wwwroot/haitian/blog/avatar/83b9c9fa1d1c368cc07131c8f988e7fe.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    海天现在每月GA赚多少?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 我的博客哪有多少啊每月5美元都不错的了


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/83b9c9fa1d1c368cc07131c8f988e7fe.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        $5 已经很高了。。。。我现在刚努力到7刀。


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          额 是吗
          我现在两个网站呢 而且说到5 也是有点牵强的


  21. Warning: copy(/home/wwwroot/haitian/blog/avatar/6ca915462446f456fbd0aee43069edd2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    百度我可没有管他。。 没挂上去。。

    我Google 最多一次单价出现过1美刀的呢。。 哈哈。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      一次单价1美元……那是什么广告啊


  22. Warning: copy(/home/wwwroot/haitian/blog/avatar/971c5311eb70bddea71b423750c81e21.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    :razz: 最近也研究了一把广告管家!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      恩 百度广告管家 感觉还是很不错的~


  23. Warning: copy(/home/wwwroot/haitian/blog/avatar/ae1d9cb02574d579039efc62a447f2f3.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我百毒快要能付款了,结果换域名之后新域名死活审核不通过,弄得还有几十块钱在里面拿不出来……


  24. Warning: copy(/home/wwwroot/haitian/blog/avatar/3e65add30eaf3de5c1955d1f309c7574.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    刚好百度的代码要更新值得去试下!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      这个是百度管家的……


  25. Warning: copy(/home/wwwroot/haitian/blog/avatar/d4aa12519670fe291cdcfcae3aa792a4.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    现在GA每月有多少啊


  26. Warning: copy(/home/wwwroot/haitian/blog/avatar/dd1635e688b764b024cfbead86871c54.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    博主对广告还挺有研究的


  27. Warning: copy(/home/wwwroot/haitian/blog/avatar/d9c4dfde2a48f5bb4df98b5a2b1c2dc7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    多谢分享哦

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

« 二级域名利用htaccess301转向到同一空间域名 电影各个版本的意思 »