Skip to content

Normalize equivalent HTML entities #211

@fulldecent

Description

@fulldecent

Issue: The minifier preserves whichever entity encoding was in the input, rather than normalizing to a canonical form.

Example:

const opts = { collapseWhitespace: true, removeComments: true };

await minify('<a>&#38;</a>', opts);  // Output: <a>&#38;</a>
await minify('<a>&amp;</a>', opts);  // Output: <a>&amp;</a>

Both & and & represent the same character (&), but the minifier produces different outputs.

Expected behavior: A minifier should produce identical output for semantically identical input. Since & and & are equivalent, the output should be normalized to one form.


Implementing the behavior in this issue would not improve the test score results on the homepage. But they improved the compressed result. Similar to existing features that are motivated by this: https://github.com/terser/html-minifier-terser?tab=readme-ov-file#sorting-attributes--style-classes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions