Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why @import is not advisable to link css?

Why @import is not advisable to link css? What @import can't do which can be done by <link> and does @import have any incompatibility with browsers?

What in <Link> make it's advisable? And is there any specialty in @import which is useful?

Should we always ,always use <link>?

like image 369
Jitendra Vyas Avatar asked Feb 10 '10 12:02

Jitendra Vyas


People also ask

Does @import work in CSS?

The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.

What is the difference between link and @import in CSS?

Linking is the first method for including an external style sheet on your web pages. It is intended to link your page with your style sheet. It is added to the head of your HTML document. Importing allows you to import one style sheet into another.

What is the purpose of @import CSS?

The @import CSS at-rule is used to import style rules from other stylesheets.

Why is @import only at the top in CSS?

A style sheet that is imported into another one has a lower ranking in the cascading order: the importing style sheet overrides the imported one. Programmers may recognize this as the same model as in Java, Modula, Object-Pascal, Oberon and other modular programming languages.


1 Answers

Here's a link to an article that talks about performances and <link> vs @import : don’t use @import ; quoting a small portion of it :

use LINK instead of @import if you want stylesheets to download in parallel resulting in a faster page.

It's not that old (it's from April 2009 -- i.e. less than one year ago), so it should still be mostly true -- and it's written by Steve Souders, whose name is quite well-known when it comes to front-end performances.


On a more subjective point, I quite prefer using several <link> from my main HTML file : this way, I am able to see in only a quick glance what css files are called -- either looking at the template file on the server, or looking at the generated HTML source on the client side.

like image 76
Pascal MARTIN Avatar answered Oct 08 '22 16:10

Pascal MARTIN