# Minify and merge CSS, JavaScript and HTML

> Static files and HTML responses are minified automatically; use MERGE() to serve several files as one and the $minify settings to switch it off.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 194c1898038bdd990369cbcb263bcd01f76642eea7059467e5d1544e067099d9
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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.

```css public/css/app.css
/* the page style */
body {
	margin: 0;
	color: #000000;
}
```

```js public/js/app.js
// greeting
function hello(name) {
	var message = 'Hello ' + name;
	return message;
}
```

```js public/js/library.min.js
function   untouched ( ) { return  1 }
```

```js public/js/two.js
function two() { return 2; }
```

```js 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>');
}
```
