Forum Moderators: not2easy

Message Too Old, No Replies

Difference between @import and <link rel>

         

asantos

2:35 am on Jun 23, 2006 (gmt 0)

10+ Year Member



Hi.
Is there a performance difference between:

A)
<link rel="stylesheet" type="text/css" media="screen" href="temp.css" />

...and...

B) @import url("temp.css");

dwighty

2:45 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



My understanding is that the <link.... /> is better understood by webbrowsers where as the @ import is not understood by the older browsers such as netscape 4.x etc

Personally I would use the @import especially when adding several style sheets.

kiwibrit

3:40 pm on Jun 23, 2006 (gmt 0)

10+ Year Member



Using the two together does mean you can have simple styling for all browsers, and extra styling for more modern ones. OTOH, very few if your users will be using Netscape or IE4.

Fotiman

6:40 pm on Jun 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I believe you also run the risk of seeing a Flash Of Unstyled Content (FOUC) using the import method if you don't have some JavaScript tag as well (if memory serves me correctly).

I just use the link method. It's reliable. Though some times I might use link to link in a main CSS file, and that CSS file might use import to pull in some other CSS files. Of course, you could just import the main one as well, but like I said there's an FOUC risk.

encyclo

6:50 pm on Jun 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no real performance difference between the two methods (as this was your initial question). The @import method became popular a few years back as a way of hiding styles from version 4 browsers (specifically Netscape 4). However, these browsers are dead now, and as Fotiman says above, there is the "FOUC" problem in IE6 when using @import.

I usually use the

link
element within the HTML document, reserving @import when calling a second stylesheet from within another stylesheet.

henry0

8:36 pm on Jun 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



encyclo,
since I often use two sheets I like the idea
but do not figure its coding
how do I insert the @ second sheet
within for ex:
<<<
<link rel="stylesheet" type="text/css" media="screen" href="temp.css" />
>>>

encyclo

1:16 am on Jun 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use
@import
within your existing stylesheet - the only restriction is that the
@import
must precede any other CSS rules.

So your temp.css file will look like this:

@import "other.css";

html {
margin:0;
/* other rules follow */
}

etc.

henry0

11:20 am on Jun 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it, thanks