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