Javascript Blocking – Loading js dynamically

Recently found a bit about how to improve load speeds of web pages using CSS Sprites – a related issue is the loading of Javascript files, which always happens one at a time. So that means that while your browser is fetching and processing a .js file everything else is put on hold until the file load is completed.

One solution – as described here – is to dynamically inject the src files using inline javascript.
There are some potential issues around this, with “race conditions” – where for example and inline js call in the HTML is executed before a required .js file is ready.
Interestingly the YSlow extension recommends combining js files into one, and loading at the end of your HTML page – which might be the bullet proof way of doing this, or the best compromise at least.
Also this generally makes sense as you would normally wait for the DOM to load before executing any javascript.

Finally it seems that newer versions of most browsers are changing the way js is loaded, so this whole discussion may soon be obsolete.

Advertisements

One Response to Javascript Blocking – Loading js dynamically

  1. Pingback: CSS Sprites and SpriteMe « Blog Bustin' .NET Beats

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: