views:

42

answers:

2

I have a one page web application, which means alot of javascript. External scripts like facebook connect etc most visitors wont use, so i'd like to know the BEST method of loading js files on an event (click, hover, timer etc). Idealy with jquery.

+1  A: 

Generate a <script> element, append it to document.body

Having one, single, minified, gzipped script probably isn't going to be that significant a bandwidth cost though.

David Dorward
some scripts i have to have separely as they're not hosted by me (like google analytics)
Haroldo
Are you really planning to load Google Analytics code on a conditional basis?!
David Dorward
+2  A: 

jQuery has getScript() function.

jQuery.getScript( url, [ success(data, textStatus) ] )
Mendy
+1 - question states with jQuery ...
James Westgate