CSS Load Performance optimizations

Source: Internet
Author: User

The CSS file to be used for the first screen page is loaded on the page header, and the CSS of other modules can be loaded asynchronously: LOADCSS and preload.

About preload, advance 2 articles for everyone to see:

1. Pre-load content by rel= "preload": https://developer.mozilla.org/zh-CN/docs/Web/HTML/Preloading_content

2, Preload's W3 document: https://www.w3.org/TR/preload/

For some CSS that isn't loaded on the first screen, we can do the following:

<link rel="preload" href="path/to/haorooms.css"as ="style" onload="this.rel= ' stylesheet '">

Prevent the browser to prohibit JS, for insurance purposes, can also be as follows

<link rel="preload" href="path/to/haorooms.css"as ="style" onload="this.rel= ' stylesheet '"> <noscript><link rel="stylesheet" href="path/to/ Haorooms.css"></noscript>

To avoid some browsers calling handlers rel= ' stylesheet ' This property, we generally recommend the following notation:

 <link rel= " preload  "  href= " path/to/ Haorooms.css   " as  ="  style   " onload=< Span style= "COLOR: #800000" > " this.onload=null;this.rel= ' stylesheet ' " Span style= "COLOR: #800000" > " ><noscript><link rel="  stylesheet   " href= " path/to/haorooms.css  "  ></ Noscript> 

For better compatibility with rel=preload, you can use LOADCSS, github address: Https://github.com/filamentgroup/loadCSS

So, without regard to browser compatibility issues (consider compatibility issues, you can use LOADCSS, not many demos here), we re-optimized the above code:

"stylesheet"href="/First screen loading Css.css"> <link rel="preload"href="/Not the first screen loaded css.css"  as="style"Onload="this.onload=null;this.rel= ' stylesheet '">class="Comments">...</section> <sectionclass="About-me">...</section> <footer>...</footer></body>

Transferred from: Https://www.tuicool.com/articles/Yfeeu2J

CSS Load Performance optimizations

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.