diff --git a/Cargo.toml b/Cargo.toml index 7cc0d7e..18150f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json", "fmt"] } tower = "0.4" tower-cookies = "0.10" -tower-http = { version = "0.6", features = ["limit", "set-header", "trace"] } +tower-http = { version = "0.6", features = ["compression-gzip", "limit", "set-header", "trace"] } slug = "0.1.6" url = "2" uuid = { version = "1", features = ["v4"] } diff --git a/src/application/routes/app/mod.rs b/src/application/routes/app/mod.rs index 19d7e84..c6043f6 100644 --- a/src/application/routes/app/mod.rs +++ b/src/application/routes/app/mod.rs @@ -43,49 +43,70 @@ async fn scan_redirect() -> Redirect { async fn styles() -> impl IntoResponse { ( - [("content-type", "text/css; charset=utf-8")], + [ + ("content-type", "text/css; charset=utf-8"), + ("cache-control", "public, max-age=604800"), + ], include_str!("../../../../static/css/styles.css"), ) } async fn webauthn_js() -> impl IntoResponse { ( - [("content-type", "application/javascript; charset=utf-8")], + [ + ("content-type", "application/javascript; charset=utf-8"), + ("cache-control", "public, max-age=604800"), + ], include_str!("../../../../static/js/webauthn.js"), ) } async fn photo_capture_js() -> impl IntoResponse { ( - [("content-type", "application/javascript; charset=utf-8")], + [ + ("content-type", "application/javascript; charset=utf-8"), + ("cache-control", "public, max-age=604800"), + ], include_str!("../../../../static/js/components/photo-capture.js"), ) } async fn searchable_select_js() -> impl IntoResponse { ( - [("content-type", "application/javascript; charset=utf-8")], + [ + ("content-type", "application/javascript; charset=utf-8"), + ("cache-control", "public, max-age=604800"), + ], include_str!("../../../../static/js/components/searchable-select.js"), ) } async fn favicon() -> impl IntoResponse { ( - [("content-type", "image/x-icon")], + [ + ("content-type", "image/x-icon"), + ("cache-control", "public, max-age=604800"), + ], include_bytes!("../../../../static/favicon.ico").as_ref(), ) } async fn favicon_light() -> impl IntoResponse { ( - [("content-type", "image/svg+xml")], + [ + ("content-type", "image/svg+xml"), + ("cache-control", "public, max-age=604800"), + ], include_str!("../../../../static/favicon-light.svg"), ) } async fn favicon_dark() -> impl IntoResponse { ( - [("content-type", "image/svg+xml")], + [ + ("content-type", "image/svg+xml"), + ("cache-control", "public, max-age=604800"), + ], include_str!("../../../../static/favicon-dark.svg"), ) } diff --git a/src/application/routes/mod.rs b/src/application/routes/mod.rs index e13fa18..2f487c1 100644 --- a/src/application/routes/mod.rs +++ b/src/application/routes/mod.rs @@ -9,6 +9,7 @@ use axum::http::{HeaderValue, StatusCode}; use axum::response::Html; use tower::ServiceBuilder; use tower_cookies::CookieManagerLayer; +use tower_http::compression::CompressionLayer; use tower_http::limit::RequestBodyLimitLayer; use tower_http::set_header::SetResponseHeaderLayer; use tower_http::trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer}; @@ -62,7 +63,8 @@ pub fn app_router(state: AppState) -> axum::Router { .layer(SetResponseHeaderLayer::overriding( axum::http::header::STRICT_TRANSPORT_SECURITY, HeaderValue::from_static("max-age=63072000; includeSubDomains"), - )), + )) + .layer(CompressionLayer::new().gzip(true)), ) .with_state(state) }