keysquash

0.0.0 • Public • Published

keysquash experimental

Keysquash is an experimental JS "compression" pass that stores an index of long, frequently used key names (e.g. addEventListener) and refers to that instead.

For example:

document.body.addEventListener('mousedown', function(e) {
  console.log('down', e.offsetX, e.offsetY)
})
document.body.addEventListener('mouseup', function(e) {
  console.log('up', e.offsetX, e.offsetY)
})

Would be transformed into this:

(function($__ks_) {
  document.body[$__ks_._]('mousedown', function(e) {
    console.log('down', e[$__ks_.$], e[$__ks_.a])
  })
  document.body[$__ks_._]('mousedown', function(e) {
    console.log('down', e[$__ks_.$], e[$__ks_.a])
  })
})({
    "_": "addEventListener"
  , "$": "offsetX"
  , "a": "offsetY"
})

Which can then get minified using uglifyjs -cm for further savings.

In practice it's a little smarter about making sure that replacing keys provides a file size improvement too, but make sure to double check this.

This is only worth using in special cases such as js13kgames. I'm not sure of all of the side-effects yet.

Installation

npm install -g keysquash

Usage

cat index.js | keysquash | uglifyjs -cm

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.0
    0

Package Sidebar

Install

npm i keysquash

Weekly Downloads

0

Version

0.0.0

License

MIT

Last publish

Collaborators

  • hughsk