how to dynamically add styles from CMS during build time
Unanswered
Lancashire Heeler posted this in #help-forum
Lancashire HeelerOP
Hi,
I am trying to find a solution to add styles during build time coming from CMS. I am able to achieve the result but it not ideal.
The styles are fetched from an external CMs via api. I’ve used css in js to add these styles and it works too.
The problem is delayed styles. I think the styles are fetched later once the page is loaded. That’s adds layout shift to page.
How can I add style tag in server generated html.
I am using nextjs 13.5
I am trying to find a solution to add styles during build time coming from CMS. I am able to achieve the result but it not ideal.
The styles are fetched from an external CMs via api. I’ve used css in js to add these styles and it works too.
The problem is delayed styles. I think the styles are fetched later once the page is loaded. That’s adds layout shift to page.
How can I add style tag in server generated html.
I am using nextjs 13.5
3 Replies
How can I add style tag in server generated html.In a random server component, you can do the following:
const css = fetchStyles();
return <style>{css}</style>with static site generation, you can statically fetch and attach the styles into your page
Lancashire HeelerOP
Thanks. I think I tried this and it gives hydration error. Also., will it automatically move the style tag to head tag?
No, it won’t add the style tag to head