Implementing Critical CSS #942
Replies: 1 comment 3 replies
-
First off, I'd just like to mention that you should make sure you can benefit from critical CSS before implementation. I'm not sure if you were a As for implementation, yes, that approach is reasonable. I'm not quite sure how Critters injects the built style tag, but you can use our prerendering API to inject this into the head of the HTML doc, rather than the body. The following is just a psudo code example: export async function prerender(data) {
const { html } = await prerender(<App {...data} />);
const criticalCSS = await critters.process(html);
return {
html,
head: {
elements: new Set([
{
type: 'style',
props: { children: criticalCss },
},
]),
},
}; But indeed, I seem to recall we had a bit of poor detection there on the Node builtins w/ prerendering. You should be able to instead to use the |
Beta Was this translation helpful? Give feedback.
-
I am setting up a project in WMR, and want to get the basics done right. It was really smooth sailing initially, but I got stuck trying to inline critical CSS.
How would you go about inlining critical CSS?
My initial idea was to extend the
prerender
export to run the rendered HTML through Critters before returning it:However this fails with
Error: path is a Node built-in - WMR does not polyfill these
, which strikes me as a bit odd—It was my impression that theprerender
export only ever runs on the server, and shouldn't need polyfilling?Beta Was this translation helpful? Give feedback.
All reactions