Crates.io | axum_html_minifier |
lib.rs | axum_html_minifier |
version | 1.0.2 |
created_at | 2025-01-18 15:34:03.986275+00 |
updated_at | 2025-03-20 16:34:05.422479+00 |
description | This crate allows you to includes a custom middleware that minify HTML outcome of a Response in your axum application. The middleware intercepts responses body and minify the entire content. So, we can send fewer packets to the client and increase our throughput. |
homepage | |
repository | https://gitlab.torproject.org/mateolafalce/axum_html_minifier |
max_upload_size | |
id | 1521864 |
size | 82,999 |
This crate allows you to includes a custom middleware that minify HTML outcome of a Response in your axum application. The middleware intercepts responses body and minify the entire content. So, we can send fewer packets to the client and increase our throughput.
cargo add axum_html_minifier
Then add html_minifier in your middleware layer, for example:
use axum::{middleware, Router};
#[tokio::main]
async fn main() {
let html = std::fs::read("examples/index.html").unwrap();
let app = Router::new()
.route(
"/",
axum::routing::get(|| async move { axum::response::Html(html) }),
)
//.layer(middleware::from_fn(OTHER_MIDDLEWARE_RULE))
.layer(middleware::from_fn(axum_html_minifier::html_minifier));
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}
cargo run --example minify --features DEBUG
When visiting http://127.0.0.1:3000/
, the response will show you the comparison between a raw response and a minified response with this crate.
This project is licensed under the GPLv3 License. See the LICENSE file for details.