Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So normally javascript files are loaded using the tag.

But how can you bind the loading of scripts files(For some secondary features like searching) to the document ready event?

And is it generally a good way to minimize your page's response time?

(sorry maybe I should ask on SO, but I do want to hear from people that mange the server.)

share|improve this question

closed as off topic by Zoredache, Magellan, rnxrx, Iain Oct 15 '12 at 20:02

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

i think it is using the $.getScript('xxx.js'); function. Anyway further comments are welcomed. – StCee Oct 12 '12 at 17:52
If you look at the right site, and actually do a search there you will see there are lots of questions already covering this ground. – Zoredache Oct 12 '12 at 18:31

You can do this by javascript. Basically you're modifying the DOM to add a javascript source at runtime.

If you're using Google Analytics, you can see that they are using this for adding the necessary JS code to the page:

<script type="text/javascript">

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.