Load your advertisements after your content

Status
Not open for further replies.

Osiris

Golden Master
Messages
36,817
Location
Kentucky
Source: Load your advertisements after your content

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.
In the end, I decided to load the ad at the bottom of the page, right before the “” tag, and then use javascript to “transfer” the contents to where I need it do be, while keeping the source hidden. This is achieved using the “document.getElementById” method, read on to take a look at a specific example.
 
Status
Not open for further replies.
Back
Top Bottom