I didn't have much use for loading ads after my content, since on most of my sites and those I worked on, they were near the end of the code anyway, but while working on a site today I ran into a problem. There is an ad at the top of the design which tends to load slowly.
I have specific requirements that the site should be as fast as possible, so I had to devise a way of loading the ad last. I went through some methods I found online after things off the top of my head didn't work, but none helped, so I came up with my own code for it.
I am not taking credit for this, so if you did this before me feel free to let us know, but I did arrive at it on my own. The methods you could try is the "defer" attribute, which defers loading to the end of the page load, however, this had no effect at all. You can also try a "window.onload", but this didn't help either. With any other function combinations the ad either loaded as usual or did some weird stuff.
<div id="top_ad_loader" style="display:none;">
Ad code in here
document.getElementById("top_ad").innerHTML = document.getElementById("top_ad_loader").innerHTML
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.