Skip to content

Component styles are not inlined to the page #14653

@pi0

Description

@pi0

Context: With Nuxt 2, bundled components in the server had matching styles that could make it possible to inline <style> tags to the HTML response of the server for faster content paint.

In Nuxt 3 and using vite, the server bundle has no information about styles but only matching chunk ids. Therefore best we could do is to add <link rel="preload" as="style"... to trigger browser prefetching styles but this is not best for performance because the network request is cascaded:

image

With Nuxt 2, with (opt-in) css-extraction, we could enable HTTP 2/Push as an alternative but well.. It is dead

Another alternative is that we could somehow integrate bundle-renderer (or use a nitro render:html hook) to fetch styles (off the client public/ assets) and inline them on the fly.

Another limitation is with Component Islands (nuxt/framework#5689) that are essentially server-side components. In order to allow components having style, we have to use a hack to use a plugin (like this) that extract styles/imports and build them to the client bundle and use prefetch links.

Ideal solution, is to make vite server build containing styles in the bundle and able to directly render them.


Remarks: Webpack 5 builder with Nuxt 3 seems actually has this information in server bundle (but we don't use it)

image

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions