I embed a google AD code in my asp.net webpage, it causes my webpage to load slow.
Is there way to load the Google AD code in background? I hope to display other content of we开发者_C百科bpage first and display google AD last.
<script type="text/javascript"><!--
google_ad_client = "pub-5823168326939016";
/* HiCalc 234x60 On 10-10-22 */
google_ad_slot = "1050696847";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Theoretically, you can.
Solution 1: don't directly include AD code to the page, but fetch it when page is loaded using javascript/AJAX (jQuery.get() will work just fine) and insert it in the page. I have tested, and the code loaded by ajax techniques gets executed when added to page DOM (Document Object Model - page content).
Solution 2: change the AD code, just surround it with some content element, like <textarea>(AD code goes here)</textarea>. Then, when the page loads, run a javascript code, which fetches the TextArea content and adds it to page DOM.
Note: I am not 100% sure this will work as expected on all the browsers, but it should.
Note2: I am not 100% sure what rules are forced by Google AdSense, and maybe this workaround violates some of them... But I think it is ok :-)
EDIT:
Here is code for the page:
<script language="javascript" type="text/javascript">
jQuery(document).ready(function () {
jQuery.get('/AdCode.aspx', null, function (data) {
jQuery('.ad-code-container').html(data);
});
});
</script>
<div id="d1" class="ad-code-container">
</div>
Here is code for AdCode.aspx file:
<@ Page Language="C#" Leave here whatever your app has %>
<script type="text/javascript">
google_ad_client = "pub-5823168326939016";
google_ad_slot = "1050696847";
google_ad_width = 234;
google_ad_height = 60;
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
I hope this helps.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" type="text/javascript"></script
you need to use word async in script code to load ad async
精彩评论