Embedding styles into custom components - thoughts please
We have a bunch of custom components that we use on our site. This is probably the case for everyone! Some components added to almost every 'page' and some are specific to one 'page'. For example, we have some jQuery to make user badges more accessible on the 'User Badges Page'. It is contained in a custom component and it is only required on that one 'page'. We also have some CSS to style the '.lia-user-badge-display-card' class (for example) but it is in the global CSS.
Would it be better to add a <style> tag to 'custom.userBadgesPage' and embed the styles into the component so that the styles only load when the page is loaded? In some cases, we're only talking a few lines so its no big deal, but in other cases the page-specific CSS is over 200 lines.
Since Lithium pages are made up of components, it makes sense to me to have the component carry the JavaScript AND styles so that this code is only loaded when the page is called rather than parse the styles (in the global CSS) for every page on our site.
I have nix/nil/nada skills with page load/performance or the like but my reading suggests that CSS stops anything else from loading while it is parsed. I'm hoping a guru or two will have some insights into this question that might help me decide whether or not to undertake a 'CSS rationalisation' program (move code chunks into components) or not (leave them in the global CSS). All thoughts/tips/warnings are welcome.
Thanks in advance
Paul (Tasmania)
PAULEM - This is definitely an option and something that can be leveraged to minimize the additional/unwanted CSS code that gets loaded on each page. Having said that, you can measure the performance of the pages with both the options using the Lithium toolbox and analyze which of these works better and efficiently.
The toolbox gives the core insights and will get the job done for you.
I hope this helps.