HTML Minifier
This library can help you generate and minify your HTML code at the same time. It also supports to minify JS and CSS in <style>, <script> elements, and ignores the minification of <pre>, <code> and <textarea> elements.
HTML is minified by the following rules:
- ASCII control characters (0x00-0x08, 0x11-0x1F, 0x7F) are always removed.
- Comments can be optionally removed. (removed by default)
- Useless whitespaces (spaces, tabs and newlines) are removed.
- Whitespaces (spaces, tabs and newlines) are converted to a single
'\x20'or a single '\n', if possible. - Empty attribute values are collapsed. (e.g
<input readonly="">=><input readonly>) - The inner HTML of all elements is minified except for the following elements:
<pre><textarea><code>(optionally, minified by default)<style>(if thetypeattribute is unsupported)<script>(if thetypeattribute is unsupported)
- JS code and CSS code in
<script>and<style>elements are minified by minifier.
The original (non-minified) HTML doesn't need to be completely generated before using this library because this library doesn't do any deserialization to create DOMs.
Examples
use HTMLMinifier;
let mut html_minifier = new;
html_minifier.digest.unwrap;
html_minifier.digest.unwrap;
html_minifier.digest.unwrap;
html_minifier.digest.unwrap;
html_minifier.digest.unwrap;
assert_eq!;
use HTMLMinifier;
let mut html_minifier = new;
html_minifier.digest.unwrap;
assert_eq!;
use HTMLMinifier;
let mut html_minifier = new;
html_minifier.digest.unwrap;
assert_eq!;
Write HTML to a Writer
If you don't want to store your HTML in memory (e.g. writing to a file instead), you can use the HTMLMinifierHelper struct which provides a low-level API that allows you to pass your output instance when invoking the digest method.
use HTMLMinifierHelper;
use File;
use Read;
let mut input_file = open.unwrap;
let mut output_file = create.unwrap;
let mut buffer = ;
let mut html_minifier_helper = new;
loop
Crates.io
https://crates.io/crates/html-minifier