On the difference between link and @import

Source: Internet
Author: User

In CSS operations, there are 2 ways to introduce CSS from the outside,link and @import.

Here are the differences between the two ways and the conclusion:

Difference:

1. Load Order
when the page loads,Linkthe CSS file introduced by the tag is loaded at the same time; @importThe imported CSS file will be loaded after the page has been loaded.

2. Compatibility
tags are HTML elements, There is no compatibility issue @import

3.link is a tag, you can load CSS files, you can also define RSS, rel connection properties, etc. ; @importis a grammar rule, only style sheets can be imported.

4. Whether you can insert a modified style with DOM actions.
The DOM can be used to insert the link tag to change the style, and @import cannot insert the style using the DOM method.

Conclusion:

It is strongly recommended that you use the link tag carefully using the @import tag.

This avoids @import resulting in a confusing download order of resource files and too many HTTP requests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.