[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThis page is outdated and refers to a deprecated version of PageSpeed Insights; the latest version is Version 5.\u003c/p\u003e\n"],["\u003cp\u003eRender-blocking external stylesheets delay page rendering, and inlining small CSS files can improve the time to first render.\u003c/p\u003e\n"],["\u003cp\u003eFor large CSS files, inline critical above-the-fold CSS and defer loading the rest to avoid blocking initial rendering.\u003c/p\u003e\n"],["\u003cp\u003eAvoid inlining large data URIs and CSS attributes within HTML elements as they can negatively impact performance and security.\u003c/p\u003e\n"]]],["PageSpeed Insights flags render-blocking external stylesheets that delay the initial render. To resolve this, inline small CSS files directly into the HTML to allow the browser to render content faster. For large CSS files, identify and inline only the above-the-fold critical CSS, deferring the rest. Avoid inlining large data URIs and CSS attributes in HTML. Tools like PageSpeed Optimization modules and loadCSS can help automate the process of inlining and deferring styles.\n"],null,["# Optimize CSS Delivery\n\n| **Deprecated** . This page was written for version 4 of the PageSpeed Insights API, which is deprecated and will be shut down in May 2019. [Version 5](/speed/docs/insights/v5/get-started) is the latest and provides both real-world data from the Chrome User Experience Report and lab data from Lighthouse.\nThis rule triggers when PageSpeed Insights detects that a page includes render blocking external stylesheets, which delay the time to first render.\n\n### Overview\n\nBefore the browser can render content it must process all the style and layout information for the current page. As a result, the browser will block rendering until external stylesheets are downloaded and processed, which may require multiple roundtrips and delay the time to first render. See [render-tree construction, layout, and paint](/web/fundamentals/performance/critical-rendering-path/render-tree-construction) to learn more about the critical rendering path, and [render\nblocking CSS](/web/fundamentals/performance/critical-rendering-path/render-blocking-css) for tips on how to unblock rendering and improve CSS delivery.\n\n### Recommendations\n\nIf the external CSS resources are small, you can insert those directly into the HTML document, which is called inlining. Inlining small CSS in this way allows the browser to proceed with rendering the page. Keep in mind if the CSS file is large, completely inlining the CSS may cause PageSpeed Insights to warn that the above-the-fold portion of your page is too large via [Prioritize Visible Content](/speed/docs/insights/PrioritizeVisibleContent). In the case of a large CSS file, you will need to identify and inline the CSS necessary for rendering the above-the-fold content and defer loading the remaining styles until after the above-the-fold content.\n\n- [Example of inlining a small css file](#example)\n- [Don't inline large data URIs](#dataURI)\n- [Don't inline CSS attributes](#CSSattributes)\n\n### Example of inlining a small CSS file\n\nIf the HTML document looks like this: \n\n```css\n\u003chtml\u003e\n \u003chead\u003e\n \u003clink rel=\"stylesheet\" href=\"small.css\"\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv class=\"blue\"\u003e\n Hello, world!\n \u003c/div\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\nAnd the resource `small.css` is like this: \n\n```css\n .yellow {background-color: yellow;}\n .blue {color: blue;}\n .big { font-size: 8em; }\n .bold { font-weight: bold; }\n```\nThen you can inline critical CSS as follows: \n\n```css\n\u003chtml\u003e\n \u003chead\u003e\n \u003cstyle\u003e\n .blue{color:blue;}\n \u003c/style\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv class=\"blue\"\u003e\n Hello, world!\n \u003c/div\u003e\n \u003cnoscript id=\"deferred-styles\"\u003e\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"small.css\"/\u003e\n \u003c/noscript\u003e\n \u003cscript\u003e\n var loadDeferredStyles = function() {\n var addStylesNode = document.getElementById(\"deferred-styles\");\n var replacement = document.createElement(\"div\");\n replacement.innerHTML = addStylesNode.textContent;\n document.body.appendChild(replacement)\n addStylesNode.parentElement.removeChild(addStylesNode);\n };\n var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame ||\n window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;\n if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); });\n else window.addEventListener('load', loadDeferredStyles);\n \u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\nThis transformation, including the determination of critical/non-critical CSS,\ninlining of the critical CSS, and deferred loading of the non-critical CSS,\ncan be made automatically by the\n[PageSpeed Optimization modules](/speed/pagespeed/module) for\nnginx, apache, IIS, ATS, and Open Lightspeed, when you enable the\n[prioritize_critical_css](/speed/pagespeed/module/filter-prioritize-critical-css) filter.\n\n\nSee also the\n[loadCSS](https://github.com/filamentgroup/loadCSS/blob/master/README.md)\nfunction to help load CSS asynchronously, which can work with\n[Critical](https://github.com/addyosmani/critical/blob/master/README.md),\na tool to extract the critical CSS from a web page.\n\n\nThe critical styles needed to style the above-the-fold content are inlined and applied to the document immediately. The full small.css is loaded after initial painting of the page. Its styles are applied to the page once it finishes loading, without blocking the initial render of the critical content.\n\n\nNote that the web platform will soon support loading stylesheets in a non-render-blocking manner, without having to resort to using JavaScript, using [HTML Imports](http://w3c.github.io/webcomponents/spec/imports/#link-type-import).\n\n### Don't inline large data URIs\n\n\nBe careful when inlining data URIs in CSS files. While selective use of small data URIs in your CSS may make sense, inlining\nlarge data URIs can cause the size of your above-the-fold CSS to be larger, which will slow down page render time.\n\n### Don't inline CSS attributes\n\n\nInlining CSS attributes on HTML elements\n(e.g., `\u003cp style=...\u003e`) should be avoided where possible, as this often leads to unnecessary code duplication.\nFurther, inline CSS on HTML elements is blocked by default with\n[Content Security Policy](http://www.w3.org/TR/CSP/) (CSP).\n\nFeedback\n--------\n\nWas this page helpful? \nYes Great! Thank you for the feedback. If you have a specific, answerable question about using PageSpeed Insights, ask the question in English on [Stack\n| Overflow](https://stackoverflow.com/questions/tagged/pagespeed-insights). For general questions, feedback, and discussion, start a thread in the [mailing list](https://groups.google.com/forum/#!forum/pagespeed-insights-discuss).\nNo Sorry to hear that. If you have a specific, answerable question about using PageSpeed Insights, ask the question in English on [Stack\n| Overflow](https://stackoverflow.com/questions/tagged/pagespeed-insights). For general questions, feedback, and discussion, start a thread in the [mailing list](https://groups.google.com/forum/#!forum/pagespeed-insights-discuss)."]]