Currently the application.css file is blocking the rendering of the website. But most of the css present in it is unused for the initial page load or not critical. So it makes sense to defer this unused css and only load the critical css for the initial page load.
Please describe the desired behavior.
The loadcss-rails gem and the critical-path-css-rails gem can be used for the same.
loadcss-rails gem helps to load all the css asynchronously by installing and making changes in the layouts where we are calling the application.css file such as application.html.erb layout.
critical-path-css-rails gem can help to only load the critical css for the inital page load. This is done by installing and configuring in the same layout. We can see it in action by precompiling our assets.
Additional context (optional)
Coverage tab showing us how much of application.css is unused.
Page SpeedInsight showing us this as the suggestion-
Hey @jywarren @emilyashley :wave: I have tested this out and seems to work pretty good just wanted to know if I should go ahead with this? :sweat_smile:
Hey @jywarren @cesswairimu @emilyashley Looking forward to your input on this :sweat_smile:
@Tlazypanda its possible styling changed and some code in application.css was not removed...but what normally happens if some styling is redefined o the specific folder css it overrides what we have at application.css i.e say we are rendering /notes if a method on application.css is redifined at notes.css the notes.css takes precedence...I would prefer we redefine what we want on the css specific file just incase another page are still using the application.css...Not sure if this makes sense or helps?
Hey @cesswairimu! Thanks a lot for your input :tada: I am not sure if I am completely able to understand what you mean(kinda slow :p) I think the gem would load the css asynchronously and for the initial page load the critical css only that it will determine from the coverage tabs...so with all the css files there might be some problem but maybe we can push to the unstable branch and test it out first? :sweat_smile: Thanks again!!
Yeah sure sounds good we can def test it on unstable. Thanks @Tlazypanda :+1:
I will be sure to check-out the gem within the week. Thanks again
Awesome thanks!
I see you might have had a few questions for review on vetting which external libraries to bring in? Not sure if this is the best place, but wanted to share what I generally look for when adding new dependencies while it is on my mind. I can check these out for you, esp if you post a list of all the ones you may be considering :) There's no need to write all of our software from scratch, but we also want to balance convenience with the control we'll have over the maintainability of our software when we add external components
Things I look for:
Bonus:
A thing I've done on teams before is created a pull request of the bare minimum code to add the dependency to a project and briefly listed the features I found useful from the library and how I might be using them. That way our asynchronous team had a place for discussion and group "vetting" of a library - each with different concerns (devops, performance, complexity etc). Dunno if that works here, but sharing what I know :)
Actually, I'll make a discussion issue out of my comment incase other people have thoughts on this unrelated to this issue :) Didn't realize I had so much to type 馃槃馃榿馃槃 (#8019)
Most helpful comment
Awesome thanks!
I see you might have had a few questions for review on vetting which external libraries to bring in? Not sure if this is the best place, but wanted to share what I generally look for when adding new dependencies while it is on my mind. I can check these out for you, esp if you post a list of all the ones you may be considering :) There's no need to write all of our software from scratch, but we also want to balance convenience with the control we'll have over the maintainability of our software when we add external components
Things I look for:
Bonus:
A thing I've done on teams before is created a pull request of the bare minimum code to add the dependency to a project and briefly listed the features I found useful from the library and how I might be using them. That way our asynchronous team had a place for discussion and group "vetting" of a library - each with different concerns (devops, performance, complexity etc). Dunno if that works here, but sharing what I know :)