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
2010-04-02 08:09:39
some scripts i have to have separely as they're not hosted by me (like google analytics)
Haroldo
2010-04-02 08:13:15
Are you really planning to load Google Analytics code on a conditional basis?!
David Dorward
2010-04-02 15:02:00
+2
A:
jQuery has getScript() function.
jQuery.getScript( url, [ success(data, textStatus) ] )
Mendy
2010-04-02 08:10:15