PageSpeed检测出的性能问题:怎么清除首屏内容中阻止呈现的css?

(1)用PageSpeed Insights检测网站性能问题:要求清除首屏内容中阻止呈现的css,参考了 https://www.carid.com/ 这个网站的css加载代码,但是当本地没有css文件缓存时,会出现一开始页面会乱掉,但是参考的网站就不会,不知道什么原因。

该图为检测性能的界面截图:
图片描述
(2)尝试参考的代码如下:

// 以下js为copy参考网站的代码

<script>var CRD = CRD || {}; CRD.readyCallbacks = [], CRD.ready = function (e) { e && "function" == typeof e && this.readyCallbacks.push(e) }, CRD.require = function (e, t) { function n(e, t) { var n = document.getElementsByTagName("head")[0], r = document.createElement("script"); r.type = "text/javascript", r.src = e, r.onload = t, n.appendChild(r) } function r() { n(a[o], function () { o++, o < a.length ? r() : t && "function" == typeof t && t() }) } if (e) { var o = 0, a = "string" == typeof e ? [e] : e; r() } }, CRD.requireCSSOrder = [], CRD.requireCSS = function (e) { function t(e, t) { var n = (a.length ? a[a.length - 1] : "") || document.getElementsByTagName("script")[document.getElementsByTagName("script").length - 1], r = t - 1; for (r; r >= 0; r--) if (CRD.requireCSSOrder[r]) { n = CRD.requireCSSOrder[r]; break } n.nextSibling ? n.parentNode.insertBefore(e, n.nextSibling) : n.parentNode.appendChild(e), CRD.requireCSSOrder[t] = e } function n(e, n) { var r = document.createElement("link"); r.href = e, r.rel = "stylesheet", setTimeout(function () { t(r, n) }, 0) } function r(e) { var t = new Date((new Date).getTime() + 54e4), n = e.split("?")[0].replace(/./(.)(..*$)/, "$1"); document.cookie = n + "=1; path=/; expires=" + t.toUTCString() } function o(e, t, n) { localStorage.setItem(e, n), localStorage.setItem(e + "_version", t) } if (e) { var a = document.querySelectorAll("style[data-url]"), i = function () { try { return localStorage.setItem("testLoc", "testLoc"), localStorage.removeItem("testLoc"), !0 } catch (e) { return !1 } }(); e = "string" == typeof e ? [e] : e; for (var l = 0; l < e.length; l++) !function (e) { var l, c, u, s, f, d = function () { for (var t = 0; t < a.length; t++) if (a[t].getAttribute("data-url") === e) return a[t]; return null }(), g = CRD.requireCSSOrder.length; if (CRD.requireCSSOrder[g] = null, i && "textContent" in document && (-1 === e.indexOf("http") && -1 === e.indexOf("//") || -1 !== e.indexOf(location.protocol + "//" + location.host))) if (l = document.createElement("style"), c = e.split("?")[0], u = e.split("?")[1] || "", s = localStorage.getItem(c) || "", f = localStorage.getItem(c + "_version") || "", d) o(c, u, d.textContent), r(e); else if (s && u === f) l.textContent = s, t(l, g); else { var p = new XMLHttpRequest; p.open("GET", e, !0), p.onreadystatechange = function () { 4 == p.readyState && (200 == p.status && p.responseText ? (l.textContent = p.responseText, o(c, u, p.responseText), t(l, g)) : n(e, g)) }, p.send(null) } else d ? r(e) : n(e, g) }(e[l]) } };</script>

// 以下代码为引用css文件

<noscript>

<link rel="stylesheet" type="text/css" href="/frontendresp/module/main.css">

</noscript>

<script>

CRD.requireCSS("/frontendresp/module/main.css");

</script>

回答:

楼主请问一下,解决这个问题了么

以上是 PageSpeed检测出的性能问题:怎么清除首屏内容中阻止呈现的css? 的全部内容, 来源链接: utcz.com/p/189594.html

回到顶部