css-inline icon indicating copy to clipboard operation
css-inline copied to clipboard

Optionally remove all `class` attributes

Open Stranger6667 opened this issue 5 years ago • 2 comments

Problem

Since everything is inlined, classes are useless and likely won't bring any benefits but occupy some space in the output. Hence I believe we can safely remove them.

Implementation

  • Add the keep_classes configuration option (everywhere, including CLI and all bindings). The default should be false.
  • Pass this config option down to the serializer and check it before writing classes to the output buffer here.

Stranger6667 avatar Jun 21 '20 13:06 Stranger6667

Hi there, would it be feasible to just remove the selectors that have been successfully inlined instead? From both the CSS and the HTML class attrs - ideally you'd only want to purge selectors that you know have been inlined and are no longer needed.

This would solve a massive paint point for us in Maizzle too (selector matching and purging is limited by PostHTML capabilities, so we can't inline or remove some more complex selectors) and I think we could switch over from Juice 🙈

cossssmin avatar Dec 30 '24 18:12 cossssmin

Hi @cossssmin !

I think it is feasible + #265 notes a similar idea of keeping some subset of the original CSS.

The implementation does not look too complex - in this block, it is possible to track what selectors are applied and build a new CSS buffer from selectors without matches. I'm not sure if splitting those by the original source (right now it is an optimization to minimize allocations), but it could also be done. And some config option to enable this behavior will be also nice to have. I don't have much capacity to work on this myself right now, but will be happy to review a PR and provide any guidance needed.

P.S. Please, let me know if there is anything else that is missing in css-inline, so you can benefit from it :)

Stranger6667 avatar Dec 31 '24 11:12 Stranger6667