-1

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.)

StCee
  • 241
  • 3
  • 14
  • 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. http://stackoverflow.com/search?q=load+javascript+runtime – Zoredache Oct 12 '12 at 18:31

1 Answers1

2

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') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
vesquam
  • 121
  • 3