Using Media to load CSS

Source: Internet
Author: User

    • By default, CSS is used as a resource that must be loaded when rendering.
    • Device type and device asking allows us to set up some CSS resources to program optional
    • All CSS resources, whether necessary or optional, will be loaded by the browser
The New York Times with Cssthe New York Times without CSS (FOUC)

The above shows the effect of loading CSS and not loading CSS styles, and the page that does not load the CSS display is also called "Flash of Unstyled Content" (Fouc).

All, the rendering of the page must require DOM and Cssom.

CSS is a necessary resource for rendering, so getting CSS resources faster will optimize rendering

CSS "Media types" and "Media Queries" Allow us to specify the conditions under which CSS is used:

A media query includes the device type and one or more expressions to indicate the characteristics of the device.

If the device satisfies media query, it pauses blocking to load the CSS resource.

<link href= "style.css" rel=  "stylesheet" ><link href=  "style.css" rel= "stylesheet" media=  "all" ><link href= " Portrait.css "rel=" stylesheet "media=" Orientation:portrait "><link href=" Print.css "rel=" stylesheet "media=" print ">               
    • The first declares that a CSS file is loaded on any type of device
    • The second declaration, all is the default parameter, and the first one is equivalent.
    • The third statement indicates that the loading of the CSS document depends on the direction of the device to determine whether to load
    • The last one is intended to be loaded in a printing device

Remember, regardless of how the media on the display of CSS, the browser has downloaded all the CSS files.

Original: https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-blocking-css?hl=en

Using Media to load CSS

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.