Next.js Discord

Discord Forum

How to preload styles to avoid blocking rendering?

Unanswered
Yellow-horned horntail posted this in #help-forum
Open in Discord
Yellow-horned horntailOP
Hello there! I am new to Next, and I'm trying to improve the performance of our app (using v14.2.20).
We use scss modules for each component, and Next automagically generates <link> elements for each page with all the needed styles.
Which is nice, but these elements are render-blocking (ie rel="stylesheet"), so I want to turn them into non-blocking (ie rel="preload" as="style").
I tried adding an inline script within the root layout to make this change on the browser, but it's not working.
This change should be done on the server while preparing the html, but I have read all the official docs, asked Copilot, GPT and generally searched all over, and still cannot find a way to do it 🫠
Can someone here give me primer a on how this could be achieved? I would greatly appreciate it :please_cat:

2 Replies

Yellow-horned horntailOP
Bumping this in the hope someone can help
Yellow-horned horntailOP
Anyone?