Question

Google loader

<script type="text/javascript">
google.load('jquery','1.7.1');
google.load('jqueryui','1.8.17');
</script>

or...

standard <script> tags

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>

Which is better and why?

Was it helpful?

Solution

The second solution is better in 99% of uses cases. The first one, you first have to load the Google API script file, then you have to load the jQuery file, which means two HTTP requests (without jQuery UI) where you need only jQuery.

If in your page, you use the Google API to something other than loading jQuery (or another Javascript library), then both solutions should be equivalent.

Something "great" with the Google API it's that you can load a dynamic version of jQuery, but I've never seen use cases for that...


For your information, you could write the script tag in this way

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

Notice I've not set the protocole in the URL. This way, if you're using HTTP then the file will be fetch by HTTP; if you're using HTTPS then it will be fetch by HTTPS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top