Skip to content

Minify global objects #5571

@keganlance

Description

@keganlance

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?

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