Cheating HTML javascript load delay
October 17th, 2008 Filed Under Good to know, Javascript, Tips & Tricks, browser, gyan, vivek
When you write the following code in your HTML:
<script language="javascript" type="text/javascript" src="www.somewhere.com/somejs.js"></script>
Your page halts till the javascript is fully loaded. Just imagine the scenario where you have more than 10 different javascript files from 3 or 4 different domains/locations on your page.That means the javascript loading is synchronous in nature. Which means, untill all the javascript is loaded and interpreted the HTML control doesn’t move to the next tag after the current script tag. Hence, you see a 4-5 seconds delay which is really embarrasing for a visitor. To overcome this problem, what you can do is make javascript to load asynchronously. Now what does that mean?That means, you load your javascript dynamically. And that means, create your script tag using createElement function and insert it in the head tag via DOM manipulation.If you do so, you can see all the script tags load parallely and your load time reduces drammatically and you see lesser time as a white page.Enjoy!!
Post Linx
Permalink | Trackback |
|
Print This Article |
Comments
Leave a Reply

