Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify global objects #5571

Open
keganlance opened this issue Jul 19, 2022 · 1 comment
Open

Minify global objects #5571

keganlance opened this issue Jul 19, 2022 · 1 comment

Comments

@keganlance
Copy link

Currently UglifyJS doesn't make the the code shorter by replacing globals with a variable reference. I wonder why this is the case.

Take something like:

(function () {
  let button = document.createElement('button');
  let span = document.createElement('span');
  span.textContent = 'something';
  button.appendChild(span);
  document.body.appendChild(button);
})();

This could easily be minified more when replacing the document references with a variable:

(function (document_) {
  let button = document_.createElement('button');
  let span = document_.createElement('span');
  span.textContent = 'something';
  button.appendChild(span);
  document_.body.appendChild(button);
})(document);

It could apply to more globals like window, navigator, and others. Is there a reason this is not included in minifiers?

@alexlamsl
Copy link
Collaborator

If you desire such a feature, please file a Pull Request so that your implementation can be benchmarked against both minified and gzipped sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants