Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 496
Bernhard Hofmann Avatar asked Feb 21 '12 08:02

Bernhard Hofmann


People also ask

How does CSS work in browser?

The browser parses the HTML and creates a DOM from it. Next, it parses the CSS. Since the only rule available in the CSS has a span selector, the browser sorts the CSS very quickly! It applies that rule to each one of the three <span> s, then paints the final visual representation to the screen.

How do you link HTML to CSS?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

How is CSS rendered?

When a web page is loaded, the browser first reads the HTML text and constructs DOM Tree from it. Then it processes the CSS whether that is inline, embedded, or external CSS and constructs the CSSOM Tree from it. After these trees are constructed, then it constructs the Render-Tree from it.


3 Answers

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.

like image 200
Linus Thiel Avatar answered Sep 28 '22 12:09

Linus Thiel


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/

like image 24
Jordan Avatar answered Sep 28 '22 12:09

Jordan


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.

like image 25
Chuck Norris Avatar answered Sep 28 '22 12:09

Chuck Norris