| Crates.io | axum_mini |
| lib.rs | axum_mini |
| version | 0.1.0 |
| created_at | 2025-08-08 16:36:07.995538+00 |
| updated_at | 2025-08-08 16:36:07.995538+00 |
| description | Lightweight HTML minifier middleware for axum web applications |
| homepage | https://github.com/tim-connect/axum_mini |
| repository | https://github.com/tim-connect/axum_mini |
| max_upload_size | |
| id | 1787023 |
| size | 44,588 |
Lightweight HTML minifier middleware for Axum applications.
This crate provides a simple middleware function that intercepts HTTP responses and minifies the HTML content before sending it to the client. By reducing HTML size, it helps improve bandwidth usage and page load times.
minify-html to perform aggressive HTML, CSS, and JS minification.Add the crate to your Cargo.toml:
axum_mini = "0.1"
Apply the middleware to your Axum router:
use axum::{middleware, Router};
use axum_mini::html_minifier;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", axum::routing::get(|| async { "<h1>Hello World!</h1>" }))
.layer(middleware::from_fn(html_minifier));
axum::Server::bind(&"127.0.0.1:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
The middleware buffers the entire HTTP response body.
It checks if the Content-Type header contains text/html.
If so, it applies HTML minification using minify-html with a preset configuration.
The minified HTML is then sent as the response body.
Non-HTML responses are forwarded without modification.
⚙️ Configuration
Removes comments
Minifies embedded CSS and JavaScript
Optimizes whitespace and tag formatting
This crate is licensed under the MIT License. Thank goodness!