perf: large cache time on immutable hashed statics
This commit is contained in:
parent
e82b6167ef
commit
41972ca1ab
6 changed files with 23 additions and 4 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -1589,6 +1589,7 @@ dependencies = [
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tower",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
"tower-sessions",
|
"tower-sessions",
|
||||||
"tower-sessions-sqlx-store",
|
"tower-sessions-sqlx-store",
|
||||||
|
|
@ -2985,9 +2986,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower"
|
name = "tower"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ sqlx = { version = "0.8", features = ["macros", "runtim
|
||||||
thiserror = "2.0.17"
|
thiserror = "2.0.17"
|
||||||
time = "0.3.44"
|
time = "0.3.44"
|
||||||
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] }
|
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
tower-http = { version = "0.6.6", features = ["fs", "trace"] }
|
tower = "0.5.3"
|
||||||
|
tower-http = { version = "0.6.6", features = ["fs", "set-header", "trace"] }
|
||||||
tower-sessions = { version = "0.14.0", features = ["signed"] }
|
tower-sessions = { version = "0.14.0", features = ["signed"] }
|
||||||
tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] }
|
tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] }
|
||||||
tracing = { version = "0.1.41", features = ["attributes"] }
|
tracing = { version = "0.1.41", features = ["attributes"] }
|
||||||
|
|
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -12,7 +12,9 @@ use std::sync::{Arc, RwLock};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::signal;
|
use tokio::signal;
|
||||||
use tokio::task::AbortHandle;
|
use tokio::task::AbortHandle;
|
||||||
|
use tower::ServiceBuilder;
|
||||||
use tower_http::services::{ServeDir, ServeFile};
|
use tower_http::services::{ServeDir, ServeFile};
|
||||||
|
use tower_http::set_header::SetResponseHeaderLayer;
|
||||||
use tower_sessions::{ExpiredDeletion, Expiry, SessionManagerLayer, cookie::Key};
|
use tower_sessions::{ExpiredDeletion, Expiry, SessionManagerLayer, cookie::Key};
|
||||||
use tower_sessions_sqlx_store::SqliteStore;
|
use tower_sessions_sqlx_store::SqliteStore;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
@ -182,7 +184,15 @@ async fn serve(port: &u32) -> Result<(), anyhow::Error> {
|
||||||
.route_layer(login_required!(Backend, login_url = "/login"))
|
.route_layer(login_required!(Backend, login_url = "/login"))
|
||||||
.merge(auth::router())
|
.merge(auth::router())
|
||||||
.merge(ics::router())
|
.merge(ics::router())
|
||||||
.nest_service("/static", ServeDir::new("./hashed_static"))
|
.nest_service(
|
||||||
|
"/static",
|
||||||
|
ServiceBuilder::new()
|
||||||
|
.layer(SetResponseHeaderLayer::overriding(
|
||||||
|
http::header::CACHE_CONTROL,
|
||||||
|
http::header::HeaderValue::from_static("public, max-age=31536000, immutable"),
|
||||||
|
))
|
||||||
|
.service(ServeDir::new("./hashed_static")),
|
||||||
|
)
|
||||||
.nest_service(
|
.nest_service(
|
||||||
"/favicon.ico",
|
"/favicon.ico",
|
||||||
ServeFile::new(format!("./hashed_static/{}", asset!("favicon.ico"))),
|
ServeFile::new(format!("./hashed_static/{}", asset!("favicon.ico"))),
|
||||||
|
|
|
||||||
5
static/alpinejs.min.js
vendored
Normal file
5
static/alpinejs.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
static/htmx-ext-response-targets.js
Normal file
1
static/htmx-ext-response-targets.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
(function(){var f;var o="hx-target-";function g(e,r){return e.substring(0,r.length)===r}function s(e,r){if(!e||!r)return null;var t=r.toString();var s=[t,t.substring(0,2)+"*",t.substring(0,2)+"x",t.substring(0,1)+"*",t.substring(0,1)+"x",t.substring(0,1)+"**",t.substring(0,1)+"xx","*","x","***","xxx"];if(g(t,"4")||g(t,"5")){s.push("error")}for(var n=0;n<s.length;n++){var i=o+s[n];var a=f.getClosestAttributeValue(e,i);if(a){if(a==="this"){return f.findThisElement(e,i)}else{return f.querySelectorExt(e,a)}}}return null}function n(e){if(e.detail.isError){if(htmx.config.responseTargetUnsetsError){e.detail.isError=false}}else if(htmx.config.responseTargetSetsError){e.detail.isError=true}}htmx.defineExtension("response-targets",{init:function(e){f=e;if(htmx.config.responseTargetUnsetsError===undefined){htmx.config.responseTargetUnsetsError=true}if(htmx.config.responseTargetSetsError===undefined){htmx.config.responseTargetSetsError=false}if(htmx.config.responseTargetPrefersExisting===undefined){htmx.config.responseTargetPrefersExisting=false}if(htmx.config.responseTargetPrefersRetargetHeader===undefined){htmx.config.responseTargetPrefersRetargetHeader=true}},onEvent:function(e,r){if(e==="htmx:beforeSwap"&&r.detail.xhr&&r.detail.xhr.status!==200){if(r.detail.target){if(htmx.config.responseTargetPrefersExisting){r.detail.shouldSwap=true;n(r);return true}if(htmx.config.responseTargetPrefersRetargetHeader&&r.detail.xhr.getAllResponseHeaders().match(/HX-Retarget:/i)){r.detail.shouldSwap=true;n(r);return true}}if(!r.detail.requestConfig){return true}var t=s(r.detail.requestConfig.elt,r.detail.xhr.status);if(t){n(r);r.detail.shouldSwap=true;r.detail.target=t}return true}}})})();
|
||||||
1
static/htmx.min.js
vendored
Normal file
1
static/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue