Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  146] [ 2]  / answers: 1 / hits: 100617  / 13 Years ago, wed, march 30, 2011, 12:00:00

Is it possible to load certain scripts like



<script type=text/javascript src=somescript.js></script>


when the rest of the page has loaded?



Imagine I have a few larger script files like this that are not needed when the page is loaded. E.g. I'm using the Google Maps API that is only used when a button is clicked (so not on page load).



Is it possible to load the rest of the page first, before processing all those script tags in my head?


More From » javascript

 Answers
92

In JQuery you could do this on document ready



$.getScript(somescript.js, function(){
alert(Script loaded and executed.);
});

[#93008] Tuesday, March 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adrianobeds

Total Points: 558
Total Questions: 118
Total Answers: 116

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;