Skip to content

Compress matomo.js via Closure Compiler instead of YUI Compressor #20964

@rr-it

Description

@rr-it

Summary

The use of Closure Compiler (CC) has some benefits over YUI Compressor (YUI).

Sligtly smaller file size

  • piwik.js minified: CC 51.8 KB vs. YUI 66.3 KB
  • piwik.js minified and gzipped: CC 18.9 KB vs. YUI 21.5 KB

Sligtly better performance of generated JS-code

CC optimises the generated JS-code with multiple performance tweaks:

Error and Warning reports on JS code smells and errors

CC gives feedback on JS code smells and errors. See all the annotations that are suppressable.

CC can enforce ECMAScript: ECMA-262, edition 3 and thereby ensures Browser Compatibility:
java -jar closure-compiler-v20230502.jar --language_in ECMASCRIPT3 --language_out ECMASCRIPT3

Munging of private object property names

CC also munges object property names.

E.g. findContentNodesWithinNode is only used internaly inside the closure function.

var content = {
    findContentNodesWithinNode: function (node) {}
}

The call content.findContentNodesWithinNode(domNode) becomes:

  • CC: a.Bb(z)
  • YUI: a.findContentNodesWithinNode(z)

Munging of all function names (PRO & CON)

By default CC munges really all function names - and thereby also the public Tracking API names.

The munging of public function names is prevented by an extra JS-file containing an @externs annotation and the function definitions.

  • CON: externs-definitions must be created and maintained.
  • PRO: externs-definitions are created and maintained. Thereby we get a technical approach to define the public API.

See Closure Compiler: Externs and Exports

Munging of all property names in data-objects (CON)

CC munges all property names. All call-parameters that must not be changed, must be in proper quotes.

callback({request: request, trackerUrl: configTrackerUrl, success: false, xhr: this});

/* CC minified: property names changed. */
a({Ba: Cu, Bb: Cv, Bc: !1, Bd: this});
callback({'request': request, 'trackerUrl': configTrackerUrl, 'success': false, 'xhr': this});

/* CC minified: property names unchanged. */
a({request: Cu, trackerUrl: Cv, success: !1, xhr: this});

See Closure Compiler: Restrictions for ADVANCED_OPTIMIZATIONS


Related to

Metadata

Metadata

Assignees

Labels

EnhancementFor new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.Technical debtIssues the will help to reduce technical debtc: PerformanceFor when we could improve the performance / speed of Matomo.c: TrackingFor issues related to getting tracking data into Matomo.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions