Asynchronous advantages: The implementation of the ad asynchronous loading, does not affect the loading speed of the page itself!
Scope of application: text, pictures and flash type advertising material on fixed advertising position
The Federation code does not currently have asynchronous loading, but the ad bit created by Baidu's ad Butler can also build federated materials and provide a variety of loading methods that can be used with the following code if the page has been loaded with jquery
The code is as follows |
Copy Code |
$.getscript ("Http://cbjs.baidu.com/js/m.js", function () { Baidu_clb_fillslotasync ("12345", "your_id"); Baidu_clb_fillslotasync ("23456", "Your_id2"); }); |
If nested into JQuery's ready function, this kind of load advertisement will not affect the page speed, of course, the display of ads according to the page is different, there will be a certain delay. If you're looking for a website speed and don't care about how fast the ad is loading, we can even put it in a settimeout, The countdown is 1-2 seconds before the ad is triggered.
-
If you do not load jquery, you can use the native asynchronous Load method
The code is as follows |
Copy Code |
<div id= "Loadad" ></div> <div id= "Loadad1" ></div> <div id= "Loadad2" ></div> <div id= "Loadad3" ></div> <script type= "Text/javascript" src= "Http://cbjs.baidu.com/js/m.js" ></script> <script type= "Text/javascript" > Baidu_clb_fillslotasync ("u1268881", "Loadad"); Baidu_clb_fillslotasync ("u1268881", "loadad1"); Baidu_clb_fillslotasync ("u188581", "loadad2"); Baidu_clb_fillslotasync ("u126781", "loadad3"); </script> |
Effect
Of course, there is a situation, do not want to load jquery to use settimeout to do the countdown, you can refer to the Google Statistics code to write
The code is as follows |
Copy Code |
var cpro_id = "u123456"; settimeout (function () { (function () {var du = document.createelement (' script '); du.type = ' text/javascript '; du.src = ' http:// Cpro.baidustatic.com/cpro/ui/c.js '; var s = document.getelementsbytagname (' script ') [0]; S.parentnode.insertbefore (Du, s);}) (); },1000); |
JS or picture ads are loaded asynchronously
How to use:
1, place the following code in the page where you want to put the ads
The code is as follows |
Copy Code |
<div id= "MyAds" > Loading ...</div> |
2, the code will be placed at the bottom of the page, that is, the bottom of the footer,php file.
The code is as follows |
Copy Code |
<div id= "Span_myads" > Place Advertising Code </div> <script type= "Text/javascript" > document.getElementById ("MyAds"). InnerHTML = document.getElementById ("Span_myads"). InnerHTML; document.getElementById ("Span_myads"). InnerHTML = ""; </script> |
OK, so that the implementation of the first load page before loading ads, how do not affect you read it