Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What makes styles 'critical'? #17

Open
davidhund opened this issue Jul 13, 2017 · 2 comments
Open

What makes styles 'critical'? #17

davidhund opened this issue Jul 13, 2017 · 2 comments
Labels

Comments

@davidhund
Copy link

I'm not sure how usus (CSS Coverage, really) classifies styles as 'critical'.
Most other tools, I believe, look at the styles needed to render the first screen (above the fold) of content.

usus seems to take more styles as critical?

@gajus gajus added the question label Jul 13, 2017
@gajus
Copy link
Owner

gajus commented Jul 13, 2017

If you are seeing a big size difference between "critical" CSS generated by usus and CSS generated by other existing tools, chances are that the other tools are simply broken. See this issue for example:

uncss/uncss#313

The "critical CSS" that is generated by uncss is nowhere near the CSS required to load the page.

27978145-e1d7b41c-6365-11e7-8479-79bf5540b8f8

On the other hand, ūsus uses Chrome's CSS coverage tool to determine which CSS was used when loading the page. If elements below the fold have been rendered, CSS for those elements will be included too. It is up to the JavaScript application to avoid rendering those elements if they are not critical (see for example https://github.com/stratiformltd/react-loadable-visibility).

Does this sound reasonable?

I am always open to be corrected.

@davidhund
Copy link
Author

I have not tested this much t.b.h. but it sounds very reasonable.

I guess there's a balance in dealing with the critical path between size and 'functionality': while other tools might reduce critical CSS size (and therefore might render quicker, but somewhat incorrectly), CSS Coverage might use more CSS (and therefore add to the download weight but render great).

There is a threshold, I believe, where it makes less sense to inline the CSS if it's heavy: because we are essentially duplicating it. Heavy (duplicated) inline CSS + the added complete CSS might (in some cases) reduce rendering performance of the page, compared to not extracting/inlineing critical CSS at all.

In these things it's the developers' responsibility to find the proper balance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants