simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 91b0e076f22bbcd74c2624224384a916b9356ef3
parent 453924cdaee738b755894eb7d4a01792892b66d6
Author: Silas Brack <silasbrack@gmail.com>
Date:   Fri, 12 Jun 2026 22:00:23 +0200

chore: remove manual gzip, let nginx handle compression

Nginx already has recommendedGzipSettings enabled globally.
Removed the pre-compressed style.css.gz and the gzip negotiation
logic from the app. All static files now served uncompressed and
nginx compresses on the fly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
Msrc/routes.rs | 36+++++-------------------------------
Dstatic/style.css.gz | 0
2 files changed, 5 insertions(+), 31 deletions(-)

diff --git a/src/routes.rs b/src/routes.rs @@ -11,47 +11,21 @@ use crate::state::AppState; // Embed static files at compile time const STYLE_CSS: &[u8] = include_bytes!("../static/style.css"); -const STYLE_CSS_GZ: &[u8] = include_bytes!("../static/style.css.gz"); const DATASTAR_JS: &[u8] = include_bytes!("../static/datastar.js"); const VALIDATION_ENHANCER_JS: &[u8] = include_bytes!("../static/validation-enhancer.js"); -async fn serve_style(headers: axum::http::HeaderMap) -> Response { - // Check if client accepts gzip - let accepts_gzip = headers - .get(header::ACCEPT_ENCODING) - .and_then(|v| v.to_str().ok()) - .map(|s| s.contains("gzip")) - .unwrap_or(false); - - if accepts_gzip { - Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, "text/css") - .header(header::CONTENT_ENCODING, "gzip") - .header(header::CACHE_CONTROL, "public, max-age=31536000") - .body(Body::from(STYLE_CSS_GZ)) - .unwrap() - } else { - Response::builder() - .status(StatusCode::OK) - .header(header::CONTENT_TYPE, "text/css") - .header(header::CACHE_CONTROL, "public, max-age=31536000") - .body(Body::from(STYLE_CSS)) - .unwrap() - } -} - -async fn serve_js(body: &'static [u8]) -> Response { +async fn serve_static(content_type: &'static str, body: &'static [u8]) -> Response { Response::builder() .status(StatusCode::OK) - .header(header::CONTENT_TYPE, "application/javascript") + .header(header::CONTENT_TYPE, content_type) .header(header::CACHE_CONTROL, "public, max-age=31536000") .body(Body::from(body)) .unwrap() } -async fn serve_datastar() -> Response { serve_js(DATASTAR_JS).await } -async fn serve_validation_enhancer() -> Response { serve_js(VALIDATION_ENHANCER_JS).await } +async fn serve_style() -> Response { serve_static("text/css", STYLE_CSS).await } +async fn serve_datastar() -> Response { serve_static("application/javascript", DATASTAR_JS).await } +async fn serve_validation_enhancer() -> Response { serve_static("application/javascript", VALIDATION_ENHANCER_JS).await } async fn static_404() -> impl IntoResponse { (StatusCode::NOT_FOUND, "Not found") diff --git a/static/style.css.gz b/static/style.css.gz Binary files differ.