Minify and merge CSS, JavaScript and HTML
Total.js minifies what it serves without any build step. A .css or .js file from public/ is sent with comments and whitespace removed (the code is not renamed or restructured, only compacted), and a string sent with $.html() or a rendered view has its HTML comments removed and repeated spaces collapsed. A file whose name contains .min. (such as library.min.js) is considered minified already and is sent as it is.
Three settings in the config file control it, all true by default: $minifyjs, $minifycss and $minifyhtml. Set one to false to serve that type untouched, which is handy when you debug in the browser.
MERGE(url, file1, file2, ...) registers a virtual file that is the concatenation of the given files, minified. The browser makes one request instead of many. File paths are URLs of the public/ folder.
/* the page style */
body {
margin: 0;
color: #000000;
}// greeting
function hello(name) {
var message = 'Hello ' + name;
return message;
}function untouched ( ) { return 1 }function two() { return 2; }exports.install = function() {
ROUTE('GET /page/', page);
MERGE('/all.js', '/js/app.js', '/js/two.js');
};
function page($) {
$.html('<!DOCTYPE html>\n<html>\n <body>\n <!-- a note -->\n <p> Hello world </p>\n </body>\n</html>');
}