Protocol Relative URLs

March 24th, 2009

Remember the first time you realised that URLs could be relative? Did you know that they can be protocol relative too. I’m not ashamed to say that I didn’t. But, what do I mean by protocol relative?

Essentially a protocol relative URL will request external resources such as images and scripts in the context of the current pages protocol http: or https:

If, like me, you’ve been ’solving’ the issue of “mixed content” warnings with a small chunk of server-side logic you’ll be pleased to hear that all you really needed to do was something like this:

<script src="//www.example.org/script.js"></script>

Looks broken doesn’t it. I can assure you that it’s entirely valid. Get into the habit of specifying all external resource URLs as protocol relative and you’ll banish mixed content warnings forever.

More about this on http://nedbatchelder.com

Posted in Web

3 Responses

  1. Rick

    1st!

  2. Joel D'Souza

    Very helpful … thanks!

  3. links for 2009-03-25 « Amy G. Dala

    [...] Protocol Relative URLs - Jamie Thompson - Web Developer (tags: web_dev) [...]

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.