From 84d057fa1e473da091f6695f4dc801a9ee541548 Mon Sep 17 00:00:00 2001 From: Orson Peters Date: Wed, 18 Jan 2023 20:43:24 +0100 Subject: [PATCH] Reduced cachebust fingerprint to be more reasonable (#2074) * Reduced cachebust fingerprint to be more reasonable. --- components/site/tests/site.rs | 2 +- components/templates/src/global_fns/files.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index b2cce71b..323a44f1 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -777,7 +777,7 @@ fn can_ignore_markdown_content() { fn can_cachebust_static_files() { let (_, _tmp_dir, public) = build_site("test_site"); assert!(file_contains!(public, "index.html", - "")); + "")); } #[test] diff --git a/components/templates/src/global_fns/files.rs b/components/templates/src/global_fns/files.rs index 9bd652c1..968cdf2c 100644 --- a/components/templates/src/global_fns/files.rs +++ b/components/templates/src/global_fns/files.rs @@ -135,7 +135,9 @@ impl TeraFn for GetUrl { Some(compute_hash::(contents, false)) }) { Some(hash) => { - permalink = format!("{}?h={}", permalink, hash); + let fullhash = format!("{}", hash); + let shorthash = &fullhash[..20]; // 2^-80 chance of false positive + permalink = format!("{}?h={}", permalink, shorthash); } None => { return Err(format!( @@ -302,7 +304,7 @@ title = "A title" let mut args = HashMap::new(); args.insert("path".to_string(), to_value("app.css").unwrap()); args.insert("cachebust".to_string(), to_value(true).unwrap()); - assert_eq!(static_fn.call(&args).unwrap(), "http://a-website.com/app.css?h=572e691dc68c3fcd653ae463261bdb38f35dc6f01715d9ce68799319dd158840"); + assert_eq!(static_fn.call(&args).unwrap(), "http://a-website.com/app.css?h=572e691dc68c3fcd653a"); } #[test] @@ -333,7 +335,7 @@ title = "A title" args.insert("path".to_string(), to_value("app.css").unwrap()); args.insert("trailing_slash".to_string(), to_value(true).unwrap()); args.insert("cachebust".to_string(), to_value(true).unwrap()); - assert_eq!(static_fn.call(&args).unwrap(), "http://a-website.com/app.css/?h=572e691dc68c3fcd653ae463261bdb38f35dc6f01715d9ce68799319dd158840"); + assert_eq!(static_fn.call(&args).unwrap(), "http://a-website.com/app.css/?h=572e691dc68c3fcd653a"); } #[test]