Protocol Relative URLs
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


March 24th, 2009 at 12:28 pm
1st!
March 25th, 2009 at 5:27 am
Very helpful … thanks!
March 25th, 2009 at 3:02 pm
[...] Protocol Relative URLs – Jamie Thompson – Web Developer (tags: web_dev) [...]