Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (54 sloc) 2.45 KB


Namedrop is a JavaScript minifier for DOM-heavy code. It works by taking multiple DOM references and flattening their properties into a single namespace object, allowing each property name to be accessed by a 2-byte valid identifier from a0 to zz. This means that verbose methods like createDocumentFragment can be invoked without having to exist in code, which is useful for environments in which gzipping is not available (such as in code golf).



$ npm install namedrop


namedrop(code, DOM-refs, callback)

Namedrop takes the code to be minified and an array of DOM references to resolve, and calls back with the minified code. This minified code starts with a with statement on a function n, which accepts a DOM object and hashes the object's properties on itself. the end result looks like this:

n=function(){/* 101-byte namespace function*/};n(this);n(this.document);...;ORIGINAL_CODE}

so that you can have code like this:


and turn it into code like this:


This is most effective when used before something like @aivopaas's jscrush.


(Note that that this is a contrived example that actually increases code size. Since Namedrop adds at least 104 bytes of overhead for namespacing, it works best on DOM-heavy code of several hundred bytes or more.)




fs = require("fs")
namedrop = require("namedrop")

before = fs.readFileSync("./before.js", "utf8")
namedrop = require("namedrop")

refs = [

namedrop(before, refs, function(err, code) {
  if (err) throw err

  else fs.writeFileSync("./after.js", code)


n=function(a,b,c,d){for(b in a){for(c=a=0;d=b.charCodeAt(c++);a%=934)a+=c*d;n[(a+360).toString(36)]=b}};n(this);n(this[]);n(this[][n.o3]);this[][n.eq][](this[][n.e5]('script'))


Copyright (c) 2011 Jed Schmidt. See LICENSE.txt for details.

Send any questions or comments here.