简体   繁体   English

在 Next.js 中加载关键 CSS

[英]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? Next.js 中是否有办法将每个页面的关键 CSS 和非关键分开并异步加载非关键?

I am using styled-components in my pages and components + couple of external css libraries.我在我的页面和组件中使用样式组件 + 几个外部 css 库。

Thanks!谢谢!

You can use module css, but not global.您可以使用模块 css,但不能使用全局。 Global styles can only be used in _app.js, but you can import "module" css which is a built in feature.全局 styles 只能在 _app.js 中使用,但您可以导入“模块” css,这是一个内置功能。 Is this what you mean?你是这个意思吗?

// Foo.js component needing third party // Foo.js 组件需要第三方

import '@thirdparty/dist/styles.css'

// Foo.js component with module css from you // Foo.js 组件,带有来自您的模块 css

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.我不完全确定你需要什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM