Http or https when including jquery from google API

jquery

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?

Best Answer

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.