Skip to content

Optionally remove all class attributes #13

Open

Description

@Stranger6667

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.

Activity

  1. cossssmin commented on Dec 30, 2024

    @cossssmin

    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 🙈

  2. Stranger6667 commented on Dec 31, 2024

    @Stranger6667
    OwnerAuthor

    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 :)

  3. Stranger6667 commented on Dec 29, 2025

    @Stranger6667
    OwnerAuthor

    Keeping only unused css is implemented in 0.19. I’ll make releases for all bindings today/tomorrow

  4. Stranger6667 commented on Mar 5, 2026

    @Stranger6667
    OwnerAuthor

    @dedupely class removal is not implemented - my comment above was strictly about css content, not about element attributes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions