thheller / shadow-css

CSS-in-CLJ(S)
https://github.com/thheller/shadow-css
Eclipse Public License 1.0
108 stars 10 forks source link

CSS Optimizations #3

Closed thheller closed 4 months ago

thheller commented 2 years ago

The idea is do a "whole program" optimization pass similar to :advanced compilation.

Instead of emitting a dedicated selector/classname for every single (css ...) use it can and should collapse some of them together and remove duplicates. It can also generate substantially shorter names for the classes.

GZIP already does a pretty good job on the generated CSS so its not all that important but should still be done properly.

The idea is to produce a lookup map during building/optimizations that just maps the original css-id generated by the macro to the actual emitted CSS classes, eg. {"some_ns__LxCx" "aA c"}.

In CLJ this map could be read at runtime and and populate the class-defs atom which the generate macro output already references.

In CLJS this map could be fed into the build before :advanced optimizations and use the idGenerator mechanism to directly replace all references. That way the CLJS code doesn't need to do anything at runtime and doesn't even need to load the lookup table. This is also already prepared.

thheller commented 4 months ago

Same Situation as #2.