Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of @import?

Tags:

css

Can someone explain what are the benefits of using the @import syntax comparing to just including css using the standard link method?

like image 233
Chris Avatar asked Oct 02 '08 13:10

Chris


People also ask

Why do countries need to import?

Goods and services are likely to be imported from abroad for several reasons. Imports may be cheaper, or of better quality. They may also be more easily available or simply more appealing than locally produced goods. In many instances, no local alternatives exist, and importing is essential.

What is the purpose of import and export?

Exports are goods that are sold in a foreign market, while imports are foreign goods that are purchased in a domestic market. Exports and imports are important for the development and growth of national economies because not all countries have the resources and skills required to produce certain goods and services.


2 Answers

As the answerer said, it lets you split your CSS into multiple files whilst only linking to one in the browser.

That said, it's still wasteful to have multiple CSS files downloading on high-traffic websites. Our build script actually "compiles" our CSS when building in release mode by doing the following:

  • All CSS files are minified (extra whitespace and comments removed)
  • We have a "core.css" file that's just a list of @import statements; during compilation, each of these is replaced by the minified CSS of that file

Thus we end up with a single, minified CSS file in production, whilst in development mode we have the separate files to make debugging easier.

like image 63
Keith Williams Avatar answered Jan 04 '23 05:01

Keith Williams


If you use <link>s in your HTML files, all those files have to keep track of all the CSS files. This obviously makes changes and additions (both for CSS and HTML files) harder.

Using @import, you reduce a theoretically infinite number of changes down to one.

like image 21
Konrad Rudolph Avatar answered Jan 04 '23 06:01

Konrad Rudolph