What's the problem?
We are currently generating one big stylesheet for each application using Page Kit. There are two issues with this:
-
Styles which could be reused across applications are not so our users must download and process the same things over and over.
-
Styles which are not required by the current page will always be downloaded anyway.
I believe solving the first issue could have a large benefit on performance as my initial investigations seemed to show that cached styles are the fastest way to get content on screen.
The second issue may only noticeably affect applications which deliver multiple variations of pages and a range of components between them but over time our stylesheets for these apps kept growing which impacts performance.
What we currently do
Currently n-ui implements a tool for splitting CSS output based on code comments, this was originally based upon a Webpack plugin and later a PostCSS plugin. Most applications use this tool to generate "critical CSS" but some also use it to split individual components or page styles.
Using code comments was seen as a viable solution because we use a range of tools to generate and optimise our CSS and splitting on code comments meant operating on the final output. However, it is not totally reliable because output order != source order (depending on Sass mixin usage, Origami silient mode, and optimisation tools) and in the case of critical CSS, completely unmaintainable as this set of styles needed to absorb more and more in order to avoid creating jank and avoid bugs created by changes to the source-order.
We tend to use a single CSS entry point because we use Sass which must store information in a single global state.
What could we do?
At a minimum I think we should try and share as many of the shared UI styles between applications.
But how we do this I do not know. A solution based upon code comments could be resurrected but if there are more robust alternatives I would love to hear about them.
What's the problem?
We are currently generating one big stylesheet for each application using Page Kit. There are two issues with this:
Styles which could be reused across applications are not so our users must download and process the same things over and over.
Styles which are not required by the current page will always be downloaded anyway.
I believe solving the first issue could have a large benefit on performance as my initial investigations seemed to show that cached styles are the fastest way to get content on screen.
The second issue may only noticeably affect applications which deliver multiple variations of pages and a range of components between them but over time our stylesheets for these apps kept growing which impacts performance.
What we currently do
Currently
n-uiimplements a tool for splitting CSS output based on code comments, this was originally based upon a Webpack plugin and later a PostCSS plugin. Most applications use this tool to generate "critical CSS" but some also use it to split individual components or page styles.Using code comments was seen as a viable solution because we use a range of tools to generate and optimise our CSS and splitting on code comments meant operating on the final output. However, it is not totally reliable because output order != source order (depending on Sass mixin usage, Origami silient mode, and optimisation tools) and in the case of critical CSS, completely unmaintainable as this set of styles needed to absorb more and more in order to avoid creating jank and avoid bugs created by changes to the source-order.
We tend to use a single CSS entry point because we use Sass which must store information in a single global state.
What could we do?
At a minimum I think we should try and share as many of the shared UI styles between applications.
But how we do this I do not know. A solution based upon code comments could be resurrected but if there are more robust alternatives I would love to hear about them.