Principle of loading the page first and then loading the ad:
The order of opening web pages is loaded in the order of the page from top to bottom, so if you want to prevent the advertisement from affecting the opening speed of the page, you have to wait until all the pages are opened before loading the JS code. When the page is loaded, loading the ad is actually placing the JS code of the ad at the bottom of the page, and after the page content is opened, loading it into the ad code, and then using the DIV reserved on the page to output the ad.
How to use:
1. Place the following code in the page where you want to place the ad
<div >Loading…</div>
2. Place the code at the bottom of the page, that is, footer, and the bottom of the php file.
<div >Put ad code here</div>
<script type="text/javascript">
("myads").innerHTML = ("span_myads").innerHTML;
("span_myads").innerHTML = "";
</script>
OK, this will realize that the page is loaded first and then the advertisement is loaded. How can it not affect everyone's reading?
1. Can load string types and Google types
<div ></div> <script> function doad(datastr,id){ //getid(id).innerHTML = datastr; This is the writing method of native js$("#"+id).html(datastr); //This is jquery writing method} /* The above are written directly, not js code The following code uses jquery's append to load Google ads well, but Baidu's one doesn't seem to be useful. The Baidu can be loaded with the function that comes with Baidu Manager. */ function doad2(datastr,id){ $("#"+id).append(datastr); } var logo_m='<a href="/" target="_blank"><img src="///image/kongbao_370.gif" width=370 height=60 /></a>'; doad(logo_m,'logo_m'); </script>
2. Can load Google ad code
$(document).ready(function(){ $('#google_ads_1').append("" + "<script src=\"\/\//pagead/js/\"><\/script>"+ "<!-- question-side -->"+ "<ins class=\"adsbygoogle\""+ " style=\"display:inline-block;width:728px;height:90px\""+ " data-ad-client=\"ca-pub-345345345345\""+ " data-ad-slot=\"345345345\"></ins>"+ "<script>"+ " (adsbygoogle = || []).push({});"+ "<\/script>"); });
Generally, the page is fully loaded and the ads are added. Of course, Google’s new code for loading ads asynchronously is quite fast and will not be stuck on the web page.
The above are all asynchronous ad codes that load Google afterwards.
I personally don't like this character loading method, but I still like it more. The code is as follows
var botad='<script async src="///pagead/js/"></script>'; botad+='<ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-343534534" data-ad-slot="6343459"></ins><script>(adsbygoogle = || []).push({});</script>'; $(document).ready(function(){ $('#google_ads_1').append(); });
3. Can load Baidu Advertising Alliance code
Baidu Butler comes with the code for post-loading ads, based on jquery
<div ></div> <script type="text/javascript"> $.getScript("/js/", function() { BAIDU_CLB_fillSlotAsync("Advertising id, cannot be u","tonglanbd"); }); </script>