0

As most of you know, when using an external library via a CDN, let's say Google, the url often looks something like this.

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

When using this on a live site, this works perfectly. However, locally it doesn't. Changing // to https:// does the trick. (Didn't test with http.)

So, what's the catch, and what's the difference?

Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239

1 Answers1

0

// takes the current used protocol. Mainly https or http, but also any other protocol supported by the browser, such as ftp.

If you're visitig a site via https the used URL for your //-resource is https too.

See also Browser support for URLs beginning with double slash

Hecke29
  • 766
  • 6
  • 18
  • 1
    That's the catch. If you open an html file with `file:///` then any urls referenced as `//` will be tried to be loaded and needs to be accessible with `//`. – fejese Oct 21 '14 at 09:52
  • Referring to fejese's answer: If you have a local webserver and are loading `http://localhost` for example it should work. It'll not work with `file:///` – Hecke29 Oct 21 '14 at 09:53