Skip to content

Add configuration option to remove JavaScript inline comments in <script> tags #285

Open

Description

@dougtc1

When minifying HTML with minify_js=true, some inline JS comments in <script> are removed but others remain.

The following html tag

<script>
    // first comment to be removed
    cp('create', id);
    // second comment to be removed
    cp('render', {
        onFullActivation: function () {
            console.log(1);
            // Last comment to be removed
        }
    });
</script>

would be minified as:

<script>// second comment to be removed
cp(`create`,id),cp(`render`,{onFullActivation:function(){console.log(1)
// Last comment to be removed
}});</script>

when using minify_js=true.

Setting keep_comments=false only affects HTML comments so it does not help either.

This comes from minify-html/src/minify/js.rs using CommentOptions { annotation: false, ..CommentOptions::default() } and keeping some of the comments.

Could we add a configuration option (e.g. remove_js_comments, with default false to preserve current behavior) that allows us to use CommentOptions::disabled()?

I can create a PR for it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions