0

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.

2 Answers 2

4

jQuery has getScript() function.

jQuery.getScript( url, [ success(data, textStatus) ] )
Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.