2017-06-15 78 views

回答

1

如果只是爲了改進Google Pagespeed結果,您應該確定呈現上述摺疊內容所需的CSS代碼,然後將其內聯到頭部。正如本文所述:https://www.storyblok.com/tp/how-to-get-pagespeed-100

CDN對於靜態文件總是有用的,但Google Pagespeed不會測量您的CSS是否由CDN提供服務。相反,它會測量CSS是否阻止了頁面的呈現。

如果您有多個CSS文件嘗試合併它們。內聯的屏內容的CSS和插入下面的鏈接標記加載的樣式,其餘的頁面已經呈現後:

<link rel="preload" id="stylesheet" href="/assets/css/below.css" as="style" onload="this.rel='stylesheet'"> 
<noscript><link rel="stylesheet" href="/assets/css/below.css"></noscript> 

的相對=預緊需要填充工具與舊的瀏覽器。所以一定要包含以下腳本:

<script> 
/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */ 
!function(a){"use strict";var b=function(b,c,d){function e(a){return h.body?a():void setTimeout(function(){e(a)})}function f(){i.addEventListener&&i.removeEventListener("load",f),i.media=d||"all"}var g,h=a.document,i=h.createElement("link");if(c)g=c;else{var j=(h.body||h.getElementsByTagName("head")[0]).childNodes;g=j[j.length-1]}var k=h.styleSheets;i.rel="stylesheet",i.href=b,i.media="only x",e(function(){g.parentNode.insertBefore(i,c?g:g.nextSibling)});var l=function(a){for(var b=i.href,c=k.length;c--;)if(k[c].href===b)return a();setTimeout(function(){l(a)})};return i.addEventListener&&i.addEventListener("load",f),i.onloadcssdefined=l,l(f),i};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this); 

/*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */ 
!function(a){if(a.loadCSS){var b=loadCSS.relpreload={};if(b.support=function(){try{return a.document.createElement("link").relList.supports("preload")}catch(b){return!1}},b.poly=function(){for(var b=a.document.getElementsByTagName("link"),c=0;c<b.length;c++){var d=b[c];"preload"===d.rel&&"style"===d.getAttribute("as")&&(a.loadCSS(d.href,d,d.getAttribute("media")),d.rel=null)}},!b.support()){b.poly();var c=a.setInterval(b.poly,300);a.addEventListener&&a.addEventListener("load",function(){b.poly(),a.clearInterval(c)}),a.attachEvent&&a.attachEvent("onload",function(){a.clearInterval(c)})}}}(this); 
</script> 
+0

謝謝亞歷山大,rel = preload究竟是做什麼的? – gleenk

+1

它有助於瀏覽器加載異步資產。使用現代瀏覽器可以提高「互動時間」約10%https://www.w3.org/TR/2015/WD-preload-20150721/ –

相關問題