• Looks like you're getting some good compression there - it seems like a lot of work for each module though, unless it can somehow be done automatically.

    I'd imagine that your example of using var htu = exports.connect( null ); may cause some problems though. Imagine the module is actually:

    exports.connect = function(options) {
      if (!options) throw new Error("Needs options!");
      // ...
    }
    

    I think advanced optimisations could actually optimise everything out of the module, because it knows how you're using it. If it doesn't do it now, it may well do when it gets improved a bit more.

    Also, when the modules themselves are minified, they get wrapped with (function() { ... })(), which allows the compiler to rename any non-exported functions/variables, even with simple optimisations.

    Is that what you're doing for your figures here? Last I checked, the difference in size was nowhere near as big as you're getting - there does seem to be a difference between the modules at http://www.espruino.com/modules/ and the figures you have...

    I think the biggest 'win' at the moment would be to 'bundle' the whole program up into one JS file (modules and all) in the Web IDE and send that to be minified. Hopefully then it could automatically rename absolutely everything that is possible, and could even remove unused functions (which is probably the biggest source of wasted space at the moment).

    I'm not quite sure how that'd be done, but it might be that just defining require as function require(x) { return modules[x]; } would be enough - the closure compiler is pretty smart.

    (Of course the Web IDE has an offline compiler built in - UglifyJS IIRC - and if that would do similar tricks as well it'd be much faster)

About

Avatar for Gordon @Gordon started