coffeekup icon indicating copy to clipboard operation
coffeekup copied to clipboard

Smarter JavaScript compilation

Open aaronshaf opened this issue 13 years ago • 2 comments

Currrently using the --js option on the command line spits out a template as JavaScript, which is great. Unfortunately, it is bloated with unused code. If one is including 20-30 templates in an app, the cumulative size starts to add up.

div -> p "test"

... is literally at around ~8k of JavaScript, minified to 4.5k.

__ck.doctypes, ie, comment functions, etc., don't need to be included if they are not used.

Or even better, it'd be great if multiple templates were compiled into one file.

aaronshaf avatar Sep 06 '11 22:09 aaronshaf

There certainly is a lot to be done in this area.

One approach I think you could already use though is to compile your templates to pure javascript with coffee, then feed them to coffeekup.js as functions (not strings). Your example would be then downloaded as just:

templates['foo'] = function() {
  return div(function() {
    return p("test");
  });
};

And rendered with:

var html = CoffeeKup.render(templates['foo']);

mauricemach avatar Sep 20 '11 07:09 mauricemach

You might want to have a look at my 'multifile' branch on my clone of this project. It does all you asked for. I added examples and updated README to show the way to do it.

https://github.com/Zertis/coffeekup/tree/multifile

mnichols avatar Nov 17 '11 20:11 mnichols