12

Possible Duplicate:
Can I change all my links to just //?

I've learnt that I can reference CSS and JavaScript by using the "//domain/path" format rather than being specific about whether the resource should be loaded over HTTP or HTTPS. Examples:

<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

The browser then loads the resources using the same protocol (schema) as the current page.

Is this supported in all browsers, and if not, which browsers don't support it?

Community
  • 1
  • 1
Bernhard Hofmann
  • 10,321
  • 12
  • 59
  • 78
  • I have had some issues on IE7 with it. Stuff didn't load properly. But I'm not posting this as an answer because I'm not sure what the problem was again. – Rene Pot Feb 21 '12 at 08:23
  • I've often wondered about this question myself, but could I ask why you would care in the above case given that the SSL overhead would be on third party servers if you just used https:// at all times? (Perhaps beyond the ancient first https connection warning messages of old IE versions.) Of course you could be using a different (sub)domain of your own resources and hence would probably care more. – userx Feb 21 '12 at 08:23
  • @userx Good point; I should have been clearer that the resources were examples only and that the real links are to another 3rd party. We link to their https JavaScript which loads other JavaScript from an http location (possibly because the page is http??) which causes Chrome to (correctly) warn the end user and allow them to not load the insecure content. – Bernhard Hofmann Feb 21 '12 at 08:29

3 Answers3

4

Yes, but IE 6-7 will download stylesheets twice with this method. Apart from that it works in all common browsers. See Can I change all my http:// links to just //?, Paul Irish - The protocol relative URL.

Community
  • 1
  • 1
Linus Thiel
  • 38,647
  • 9
  • 109
  • 104
  • Thank you Linus. I failed to find that duplicate, but now that you've shown me I've voted to close the question as a duplicate. Or should I vote to delete it? – Bernhard Hofmann Feb 21 '12 at 08:23
  • I'm not sure about that - I'm not sure I'm entrusted to work with duplicates and stuff yet. ;) Good luck! – Linus Thiel Feb 21 '12 at 08:27
1

In general, it will work. There are edge cases in Everybody's Favorite Browser though, where if you're requesting from a non-ssl subdomain it will fail.

http://paulirish.com/2010/the-protocol-relative-url/

Jordan
  • 31,971
  • 6
  • 56
  • 67
1

According to this article.

When used on a or @import for a stylesheet, IE7 and IE8 download the file twice. All other uses, however, are just fine.

And about IE 6

The reason this doesn't work in IE6 is that the server is using SNI to deduce what certificate to return. XP (and thus IE6) doesn't support SNI in the HTTPS stack.

Chuck Norris
  • 15,207
  • 15
  • 92
  • 123