Petes techie blog

A blog written for two people. Me and You.

Protocol Relative Urls

| Comments

We do development on our test boxes using http (on our intranet) but use https on our production servers. I also use googles cdn to host the jquery files I use. The question is do I use http or https to link to them, or use javascript to change the link or perhaps get the server to create the src link. The best solution is to use protocol relative urls! Heres an example:

<script type="text/javascript" src="//"></script>

Drop the protocol and just start with double slash. The browser will then use the same protocol as the current page. NOTE: if you do this with stylesheets (css files) then IE7 & IE8 will download these files twice, I’ll need to check whether IE9 has this problem. I only really link to javascript (and media) files externally so protocol relative files work for me.