Search code examples
jquerygoogle-mapsgoogle-apigoogle-chrome-devtoolsiis-express

Why does an "http:-less" CDN reference not work when running a standalone html page?


I had this in my main (only) page's head section:

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

When I run this app/site from Visual Studio 2013/local IIS, it references jQuery fine; however, when I try to run it from Windows Explorer by 2-clicking the .html file, the google map won't load, and Chrome Developer Tools, Console window, shows "jQuery not found" errors.

Prepending the "http:" to the CDN reference like so:

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

...solves the problem. Why?


Solution

  • Without the protocol included the browser uses the the protocol of the current page. If you load the page from the file system, in this case it is file:///, so you end up looking for something like file:///ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js