CSS inline or external? Inline PK external

Source: Internet
Author: User

Now is an era that advocates structure, performance, and behavior separation. The biggest benefit is that it is easy to maintain and convenient,CodeReuse. Writing CSS and Js in HTML is like a hodgedge, which is hard to understand, has poor readability, large files, and is very difficult to maintain.

 

But is CSS inline or external? As long as we analyze its characteristics, it is not difficult to come up with an answer.

CSS inline:CSS is placed in the HTML head and surrounded by style. <Style type = "text/CSS"> </style>

CSS outreach:Put CSS in a separate file and call it in HTML. <LINK rel = "stylesheet" type = "text/CSS" href = "">.

 

We know that HTTP requests are expensive, and CSS inline operations will certainly be faster, because placing CSS in an HTML file means reducing an HTTP request. The external connection is an HTTP request, but it can be cached. When the browser loads the file, the second request is read in the cache, therefore, the second request is very fast, and the CSS of the external application can reuse the code. So is inline or external connection used? This depends on the requirement. If a page does not need to be cached, that is, this page is not very accessed, or when there are not many visits, such as the registration page, people usually only enter the page once, it is impossible for you to register the website for the first time. In other words, this page does not need to be cached. If you put CSS in the head, loading time can be shortened and user experience can be improved. For frequently accessed pages, external access is definitely the best choice.

On some large websites, such as Google and Yahoo, you can also see that CSS is written in the head. For the principle of separation of structure and behavior, we can accept CSS input in the head, as long as it is not written on the element.

Related Article

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.