Skip to content

Include “critical styles” in SSR output #392

Open
@BigAB

Description

@BigAB

This was discussed on a recent live stream (24:36).

I see a significant delay from when the HTML is sent to the client, and when the CSS arrives (when artificially throttling the network with Chrome tools at least).

The render is blocked until the CSS arrives, which undoes a big portion of the super performance gains of SSR.

Is there a way, to determine the CSS needed to render, and push it in with the HTML in a style tag?

It might look something like:

<html>
<head>
  <title>My App</title>
  <style>body { ... }, nav.header { ... }</style>
</head>
<body>
  <link rel="stylesheet" href="/dist/bundles/app/app.styles.css">
</body>
</html>
  1. The critical styles here are inlined.
  2. The rest of the main bundles styles are put into a <link> tag and added to the browser. Some browsers won't block rendering for link tags inside of the body.

Possible tools to look at for implementation ideas:

https://github.com/addyosmani/critical-path-css-tools

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions