Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented May 24, 2023

Summary

UglifyJS is ES5-only, while Terser supports newer ECMAScript versions. jQuery is authored in ES5 but jQuery 4.x will also have an ESM build that cannot be minified using UglifyJS directly.

We could strip the export statement, minify via UglifyJS and re-add one but that increases complexity & may not fully play nice with source maps.

On the other hand, switching to Terser increases the minfied size by just 324 bytes and the minified gzipped one by just 70 bytes. Such differences largely disappear among bigger size gains from the 3.x-stable line - around 2.7 KB minified gzipped as of now.

Checklist

UglifyJS is ES5-only, while Terser supports newer ECMAScript versions. jQuery
is authored in ES5 but jQuery 4.x will also have an ESM build that cannot be
minified using UglifyJS directly.

We could strip the `export` statement, minify via UglifyJS and re-add one but
that increases complexity & may not fully play nice with source maps.

On the other hand, switching to Terser increases the minfied size by just 324
bytes and the minified gzipped one by just 70 bytes. Such differences largely
disappear among bigger size gains from the `3.x-stable` line - around 2.7 KB
minified gzipped as of now.
@mgol mgol added Needs review Build Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels May 24, 2023
@mgol mgol added this to the 4.0.0 milestone May 24, 2023
@mgol mgol self-assigned this May 24, 2023
@mgol
Copy link
Member Author

mgol commented May 24, 2023

This is a pre-requisite to finalizing the exports PR (#5255).

@mgol mgol requested review from gibson042 and timmywil May 25, 2023 11:34
Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of this, but it supports my suspicion that Terser is not as good as Uglify w.r.t. output compressibility.

@mgol
Copy link
Member Author

mgol commented May 25, 2023

@gibson042 Yes, although it got better in the past year. Last time I was testing with Terser 5.14.2 (released on 2022-07-13), the numbers were +620 minified, +99 minified gzipped.

I also think it may be a good idea to compare the output of UglifyJS & Terser in more detail and work with Terser maintainers to improve it, getting closer to UglifyJS. But I wouldn't treat this as a blocker for this PR, just ground for possible future optimizations.

@mgol mgol merged commit 27303c6 into jquery:main May 31, 2023
@mgol mgol deleted the terser branch May 31, 2023 16:59
@mgol mgol removed Needs review Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels May 31, 2023
mgol added a commit to mgol/jquery that referenced this pull request Jun 27, 2023
mgol added a commit to mgol/jquery that referenced this pull request Jul 6, 2023
Also, as part of this, fix the `file` & `sources` properties of the source map
file.

Fixes jquerygh-5285
Ref jquerygh-5258
mgol added a commit that referenced this pull request Jul 10, 2023
Also, as part of this, fix the `file` & `sources` properties of the source map
file.

Fixes gh-5285
Closes gh-5286
Ref gh-5258
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

2 participants