zoukankan      html  css  js  c++  java
  • css加载优化

    <head>
      <script>
        // https://github.com/filamentgroup/loadCSS
        !function(e){"use strict"
        var n=function(n,t,o){function i(e){return f.body?e():void setTimeout(function(){i(e)})}var d,r,a,l,f=e.document,s=f.createElement("link"),u=o||"all"
        return t?d=t:(r=(f.body||f.getElementsByTagName("head")[0]).childNodes,d=r[r.length-1]),a=f.styleSheets,s.rel="stylesheet",s.href=n,s.media="only x",i(function(){d.parentNode.insertBefore(s,t?d:d.nextSibling)}),l=function(e){for(var n=s.href,t=a.length;t--;)if(a[t].href===n)return e()
        setTimeout(function(){l(e)})},s.addEventListener&&s.addEventListener("load",function(){this.media=u}),s.onloadcssdefined=l,l(function(){s.media!==u&&(s.media=u)}),s}
        "undefined"!=typeof exports?exports.loadCSS=n:e.loadCSS=n}("undefined"!=typeof global?global:this)
      </script>
      <style>
        /* The styles for the site header, plus: */
        .main-article,
        .comments,
        .about-me,
        footer {
          display: none;
        }
      </style>
      <script>
        loadCSS("/the-rest-of-the-styles.css");
      </script>
    </head>
    <body>
    </body>
    

     在上面的代码中,通过一些内联样式我们可以加速初始渲染,同时隐藏起还没有加载完样式的组件,并通过 JavaScript 异步地完成加载。剩余的 CSS 加载完后会重写.main-article中的display:none

  • 相关阅读:
    JWPlayer Uncaught Error: Invalid SRT file
    京东电商API
    map, string 强大的STL
    VFL演示样例
    sizeof小览
    Java中httpClient中三种超时设置
    Windows下Mysql5.6启用监控执行脚本的日志
    实时监控MySql状态
    实时监控mysql数据库变化
    SVN命令使用详解
  • 原文地址:https://www.cnblogs.com/beiz/p/6007725.html
Copyright © 2011-2022 走看看