Skip to content

FOUC when refreshing the page #48

Answered by ElMassimo
Matth10 asked this question in Q&A
Discussion options

You must be logged in to vote

For the reason FOUC happens in development, read this thread.

I'm not sure it will be worth the hassle, but in the spirit of providing a solution:

Something that you could try in development is to render a separate vite_stylesheet_tag that adds any critical CSS before the async scripts are loaded.

Example:

<%= vite_stylesheet_tag 'critical' if Rails.env.development? %>

Let's say that your main JS entrypoint imports other stylesheets, such as theme.css, you would then import that in critical.css:

@import "~/styles/theme.css";

Have in mind that this is only suitable for styles that you are in full control of (not dynamically injected by Vite plugins).

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
4 replies
@Matth10
Comment options

@ElMassimo
Comment options

@Matth10
Comment options

@ElMassimo
Comment options

Comment options

You must be logged in to vote
5 replies
@Matth10
Comment options

@ElMassimo
Comment options

@Matth10
Comment options

@ElMassimo
Comment options

@Matth10
Comment options

Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants