Thursday, May 10, 2012

Is linking to CSS or JavaScript without the protocol supported in all browsers?



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?


Source: Tips4all

2 comments:

  1. 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.

    ReplyDelete
  2. 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.

    ReplyDelete