Search code examples
jquerygetscript

Jquery - getScript vers. <script>..</script>


what is faster?

<script src="../js/SOME.js" type="text/javascript"></script>

OR

   $.getScript('../js/SOME.js', function (){ ... 
   // with $.ajaxSetup({ cache: true }); 

Solution

  • I'd guess that <script src="../js/SOME.js" type="text/javascript"></script> is faster, as the browser does it natively, while the second alternative first forces the browser to load the page, then use JavaScript to load the script.

    The browser might take care of caching by itself, but I'm not too certain.