axum_mini

Crates.ioaxum_mini
lib.rsaxum_mini
version0.1.0
created_at2025-08-08 16:36:07.995538+00
updated_at2025-08-08 16:36:07.995538+00
descriptionLightweight HTML minifier middleware for axum web applications
homepagehttps://github.com/tim-connect/axum_mini
repositoryhttps://github.com/tim-connect/axum_mini
max_upload_size
id1787023
size44,588
(tim-connect)

documentation

https://docs.rs/axum_mini

README

axum_mini

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.


✨ Features

  • Buffers the full HTTP response body to process HTML content.
  • Uses minify-html to perform aggressive HTML, CSS, and JS minification.
  • Integrates easily as an Axum middleware layer.

🚀 Usage

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();
}

🛠️ How It Works

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

The minifier uses a fixed configuration optimized for general use:

Removes comments
Minifies embedded CSS and JavaScript
Optimizes whitespace and tag formatting

📄 License

This crate is licensed under the MIT License. Thank goodness!

Commit count: 0

cargo fmt