Skip to content

Commit

Permalink
Reduced cachebust fingerprint to be more reasonable (#2074)
Browse files Browse the repository at this point in the history
* Reduced cachebust fingerprint to be more reasonable.
  • Loading branch information
orlp authored and Keats committed Feb 16, 2023
1 parent 0c5ffa8 commit 84d057f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"<link href=\"https://replace-this-with-your-url.com/site.css?h=83bd983e8899946ee33d0fde18e82b04d7bca1881d10846c769b486640da3de9\" rel=\"stylesheet\">"));
"<link href=\"https://replace-this-with-your-url.com/site.css?h=83bd983e8899946ee33d\" rel=\"stylesheet\">"));
}

#[test]
Expand Down
8 changes: 5 additions & 3 deletions components/templates/src/global_fns/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ impl TeraFn for GetUrl {
Some(compute_hash::<Sha256>(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!(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 84d057f

Please sign in to comment.