Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/keysquash
An experimental JS "compression" pass that stores an index of long, frequently used key names.
https://github.com/hughsk/keysquash
Last synced: 8 days ago
JSON representation
An experimental JS "compression" pass that stores an index of long, frequently used key names.
- Host: GitHub
- URL: https://github.com/hughsk/keysquash
- Owner: hughsk
- Created: 2013-08-15T03:18:09.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-15T03:18:17.000Z (about 11 years ago)
- Last Synced: 2024-10-17T16:40:11.295Z (22 days ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# keysquash [![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) #
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:
``` javascript
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:
``` javascript
(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](http://js13kgames.com/). I'm not sure of all of the side-effects
yet.**## Installation ##
``` bash
npm install -g keysquash
```## Usage ##
``` bash
cat index.js | keysquash | uglifyjs -cm
```