Skip to content

Strip comments when altering the DOM #2026

Open

Description

@whi7ed3vil

I've got some fairly complicated CSS overlays that end up in various parts of the DOM. In low resource environments, the repetitive/recursive application of these styles can become a bit bloated on a page. This is compounded by the comments left in the DOM from the original CSS. I'd request that the application default behavior is to strip comments and lexicographically condense the CSS when injecting into the DOM for faster parsing. This might be a marginal gain in most settings, but I believe in making good use of comments as these living documents are modified, and that seems opposed to the implementation strategy which allows all those useless bytes to remain recursively embedded in the live page. Over time, it does seem to cause some noticeable performance delays. Perhaps a setting would allow the purists to prevent contraction before injection? But I don't see any reason to allow comments and extra whitespace for that matter to be embedded after the injector knows what to put where.

Activity

  1. tophf commented on Dec 1, 2025

    @tophf
    Member

    Stripping of comments and whitespace in JS sounds like a much more expensive operation than doing it in the optimized native machine code inside the browser. Naturally, there may be a bug in the browser, but that should be reported and fixed, and the first step would be to verify there's a detectable difference by comparing results in devtools -> performance for your CSS's original vs minified state.

  2. tophf commented on Dec 1, 2025

    @tophf
    Member

    One possible implementation I can agree with at this point would be a [ ] minify injected CSS for performance gains option that stores the minified CSS inside the style database when a style is edited/updated. It would naturally nearly double the disk space for the database, but that's the user's decision to make.

  3. whi7ed3vil commented on Dec 1, 2025

    @whi7ed3vil
    Author

    Yes I hear you — and your second comment quite well captures what I had in mind. Doing it once upon saving is a small task vs doing it in real time multiplied by hundreds or thousands of recursions on a page that’s actively mutated would be favorable no matter how fast the browser can get the job done over JS, IMO. (Highly mutated pages are what drive the consideration, mainly.) Disk space expense is a reasonable consideration, but also a minimal expense given the typical scenario. User option is good. Thanks for your thoughts! :)

  4. Desynci commented on Mar 16, 2026

    @Desynci

    I'd request that the application default behavior is to strip comments and lexicographically condense the CSS when injecting into the DOM for faster parsing.

    If I understand what you mean, provided preprocessors can do this already. I use Stylus Lang and final <style> injected element doesn't contain any comments. However, it still requires resources to process code and remove all comment lines. I'm not sure if it happens on page load and change of style settings only, or if there're more conditions for it.

  5. tophf commented on Mar 17, 2026

    @tophf
    Member

    Preprocessors are called when changing the text of the style or its config and the result is cached in sections of the style object in storage.

  6. Desynci commented on Mar 19, 2026

    @Desynci

    Preprocessors are called when changing the text of the style or its config and the result is cached in sections of the style object in storage.

    Good to know. When does the cache storage reset, if it does? Like closing the browser, etc.

    I was afraid of bloating the style size and overusing preprocessor functions because of the possible performance hit or page load slowdown, but if you say so, it shouldn't really be a problem.

    By the way, automatic style minification might be a thing, but I'm not sure if there would be a real benefit from it, like faster style parsing by a browser or style injection speed.

  7. tophf commented on Mar 19, 2026

    @tophf
    Member

    It's a permanent part of the style object in storage, currently there's no functionality to evict it because the database is usually just a few megabytes.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions