ForgeTotal.js 5
en

Total.js 5

Minify and merge CSS, JavaScript and HTML

Total.js 5 · total5@0.0.19 performancecssjavascripthtmlminification Executed against Total.js 5

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.

public/css/app.css
/* the page style */
body {
	margin: 0;
	color: #000000;
}
public/js/app.js
// greeting
function hello(name) {
	var message = 'Hello ' + name;
	return message;
}
public/js/library.min.js
function   untouched ( ) { return  1 }
public/js/two.js
function two() { return 2; }
controllers/minify.js
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>');
}