views:

63

answers:

3

Hi,

I am using the Google visualization for drawing graphs into my website. This involves a lod of java script.

 <script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
 <script type="text/javascript">
 google.load('visualization', '1', {packages: ['annotatedtimeline']});
 </script>

These two lines of script takes at least 5 to 8 sec to load initially. How ever i use the graph feature in my website after sometime of the initial page load and not immediately. So i was wondering instead of slowing down the page load by 5 sex for the script to load can i do a lazy load of java script parallel to my page load. This will make my initial page load faster. Can this be done, if so please let me know syntax and also some link providing the documentation if any. Any kind of help is appreciated. Thanks in advance.

+2  A: 

Put all the script tags immediately before the closing body tag as per this YSlow recommendation.

Darin Dimitrov
Some of the on load scripts do not get executed untill the above scripts are loaded. This causes some UI problems on my page.
Vinodtiru
@vinodtiru, you can try to put all your SCRIPT tags in the right order before the BODY end tag, and remove the onload handling.
Mic
A: 

Put it as lower as you can at the page, meaning closer to the end tag. Your page will load all its contents before delaying further to load the JS.

henasraf
A: 

You can also experiment with the DEFER attribute and placing the script tag into a separate head tag:

http://www.hunlock.com/blogs/Deferred_Javascript

Killroy