Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading critical CSS in Next.js

Is there a way in Next.js to separate critical CSS and non critical for each page and load non-critical asynchronously ?

I am using styled-components in my pages and components + couple of external css libraries.

Thanks!

like image 335
anticol Avatar asked Feb 13 '26 02:02

anticol


1 Answers

You can use module css, but not global. Global styles can only be used in _app.js, but you can import "module" css which is a built in feature. Is this what you mean?

// Foo.js component needing third party

import '@thirdparty/dist/styles.css'

// Foo.js component with module css from you

import styles from "./Foo.module.css";

I apologize if this is not what ur looking for. I'm not entirely sure what you are in need of.

like image 166
james emanon Avatar answered Feb 15 '26 19:02

james emanon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!