tower-minify-html
A Tower layer for minifying HTML responses using minify-html.
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Example
use ;
use Cfg;
use MinifyHtmlLayer;
async
async
Features
standard(default): Enables the standardminify-htmlbackend.onepass: Enables theminify-html-onepassbackend.
Both features can be enabled at the same time.
Backends
You can choose between the standard and onepass backends using the MinifyHtmlLayerBuilder.
Standard Backend
The standard backend uses minify-html and is the default and can be used with MinifyHtmlLayer::new or the builder.
use ;
let mut cfg = new;
let layer = new;
Onepass Backend
The onepass backend uses minify-html-onepass and is faster but has more limitations. It requires the onepass feature.
use ;
let mut cfg = new;
let layer = builder
.backend
.onepass_config
.build;
Compression
When using this layer with compression (e.g., tower-http's CompressionLayer), ensure that MinifyHtmlLayer is applied before the compression layer in your code (i.e., MinifyHtmlLayer should be the inner layer). This ensures that the HTML is minified before it is compressed.
let app = new
.route
.layer
.layer;
License
MIT OR Apache-2.0