script src="//ajax.googleapis.com, where is the http?

10,756

Basically it allows the browser to determine whether to use http:// or https:// based on the protocol that your page is using. If your page is on https then it will use https to get the scripts. Because if you hard code to say http and you page is using https then the browser will throw errors telling the user that the site might not be safe for instance. Bottom line always use relative URL for scripts, images and all resources and don't hard code the http protocol.

Share:
10,756
Tony M
Author by

Tony M

I've been a part of this community for over 3 years now and it's become an essential part of my web dev toolkit. Countless hours saved from kind, knowledgeable community members and it feels great to return the favor when I can. SO for life! SOreadytohelp

Updated on June 24, 2022

Comments

  • Tony M
    Tony M almost 2 years

    I haven't been able to figure this out, but for some reason when I use the google libraries and look for a script to use (https://developers.google.com/speed/libraries/devguide#jquery), they are provided without the http... why is that? I've also noticed that google is now doing this on Youtube embed code (which causes my ckeditor youtube embed plugin to see this as an invalid src for an iframe).

    Example (without http):

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

    Why not this (with http):

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    

    I have a feeling it has something to do with merging everything over to https. Perhaps this is preparation?