---
title: Minificazione
project: Total.js V5
version: 0.0.20
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/total-js-v5/0-0-20/reference/minification/
updated: 2026-11-18T16:57:24.576Z
---

# Minificazione

> U.minify_css(), U.minify_js() e U.minify_html().

## API

### U.minify_css(css)

Type: `method`

Minifica il CSS e compila le regole annidate e le `$variables`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `css` | `String` | yes |  | Sorgente CSS. |

Returns: `String` CSS minificato.

Rimuove commenti e spazi, abbrevia `margin` e `padding` (`0 0 0 0` in `0`, `10px 20px 10px 20px` in `10px 20px`) e colori come `#FFFFFF`. Una regola che contiene solo altre regole viene espansa (`.a { .b { } }` in `.a .b{}`). Le variabili vengono dichiarate come `$name: value;` e usate come `$name`. In caso di errore la funzione registra `CSS compiler error` e restituisce una stringa vuota.

Example: Regole annidate
```js
U.minify_css('.menu {\n\t.item { color: red; }\n\t.active { font-weight: bold; }\n}');
// '.menu .item{color:red}.menu .active{font-weight:bold}'
```

Example: Variabili
```js
U.minify_css('$brand: #0066FF;\n.button { background: $brand; }');
// '.button{background:#0066FF}'
```

### U.minify_js(js)

Type: `method`

Minifica JavaScript.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `js` | `String` | yes |  | Sorgente JavaScript. |

Returns: `String` Codice minificato.

Rimuove commenti, a capo e spazi non necessari. Le stringhe restano come sono. Non rinomina le variabili.

Example: Minificare
```js
U.minify_js('if (a) {\n\tconsole.log(a); // log\n}'); // 'if(a){console.log(a);}'
```

### U.minify_html(html)

Type: `method`

Minifica l'HTML.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `html` | `String` | yes |  | Sorgente HTML. |

Returns: `String` HTML minificato.

Rimuove i commenti (non i commenti condizionali come `<!--[if IE]>`) e riduce a uno solo le sequenze di spazi tra le parole. Le interruzioni di riga e l'indentazione tra i tag vengono mantenute. Il contenuto di `<script>`, `<textarea>`, `<pre>`, `<code>` e `<readme>` non viene modificato. `<script>` e `<style>` inline vengono minificati con i minificatori JS e CSS quando `$minifyjs` e `$minifycss` sono attivi.

Example: Minificare
```js
var html = U.minify_html(source);
```
