Jump to content

javascript trick: Loading remote javascript after pageload with onload


Recommended Posts

  • Administrators



So, malin (my wife) had a problem today with a remote tracker script from www.susnet.se dident work because their server is down, this caused her blog to load extremely slow.


The solution was quite simple, instead of loading the susnet code in the middle of her site, we would load the susnet code AFTER the page have loaded using a OnLoad event.


The change look like this.


1. Change


2. Create a new javascript at the end of the page like this


function doneLoading() {


The above function will call yet another function called "loadSusnet"


3. Create the LoadSusnet javascript function and the end of the code.. like this....


function loadSusnet() {
var scriptSusnet1 = document.createElement('script');
scriptSusnet1.type	= 'text/javascript';
scriptSusnet1.src	= 'http://susnet.se/susnetstat.js';
susnet_counter_id = 60529;
//susnet_security_code = '76388'

var scriptSusnet2 = document.createElement('script');
scriptSusnet2.type	= 'text/javascript';
scriptSusnet2.src = 'http://susnet.se/susnetstat.js';
susnet_counter_id = 60529;
//susnet_security_code = '76388'


What the susnet function does is to dynamically load the remote javascript files, all this is done AFTER the page have rendered, hence the page now loads ALOT faster... - offcourse, this should be used wisefully.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...