coffeekup
coffeekup copied to clipboard
Smarter JavaScript compilation
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.
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']);
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