0

Should I do this

https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js

or

http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js

When I'm including jquery using Google's CDN?

3 Answers 3

5

Neither. Use:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>

That will use whichever protocol your page was requested with.

See my reference here.

You should use this instead of linking to your own copy of this file on your server. It saves you bandwidth as you won't have to serve this file to your users (it adds up). And it makes the experience for your users better as they won't have to spend the 500 milliseconds downloading the file. Most likely, your users will have visited another web page which references Google API and will have jQuery cached. If they haven't they will pull that file from a server close to their location minimizing round trip time.

Don't let anyone convince you that this isn't the right thing to do.

1
  • The double // without a scheme is supported by all major browsers and has been in the browsers standard for many years (maybe from the beginning.) It's a great gem and saves lots of silly (if ssl then .. else ..) type checks.
    – WaldenL
    Mar 27, 2012 at 14:40
1

You should use the same protocol that your page was accessed with.

0

In my opinion just download it to your server and use it from there.

I do not see the benefits from using a 3rd party server for that except for really high load sites.

(Many do it anyways.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .