Skip to content

Commit e86d210

Browse files
committed
fix(build) :: make frontend asset urls idempotent if nothing changed
Frontend assets were hashed via gzip's output which includes a nonidempotent/deterministc timestamp from libflate. This changes the hash on each build. Now we hash over the bundled file contents in `frontend/dist`.
1 parent d22d631 commit e86d210

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## unreleased
44

55
- Big number cards with a `color` once again display their main value in that color in light and dark themes, including values with a link. Their compact vertical padding has also been restored.
6+
- Frontend asset urls are now idempotent between builds if nothing changed in the frontend. Now browsers will only re-download frontend assets when there has been a code change in them.
67
- `cargo install sqlpage` or any build from the crates.io tarball only needs Rust and no longer needs internet access. Pre-built binaries and the Docker image are unaffected.
78
- The browser assets are now bundled as a whole, so SQLPage's own scripts are minified along with their dependencies and are no longer readable in browser devtools.
89

build.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ fn track_dist_changes() {
4040
}
4141
}
4242

43+
fn dist_path(name: &str) -> PathBuf {
44+
Path::new(DIST).join(name)
45+
}
46+
4347
fn open_dist(name: &str) -> File {
44-
let path = Path::new(DIST).join(name);
48+
let path = dist_path(name);
4549
File::open(&path).unwrap_or_else(|err| {
4650
panic!(
4751
"Unable to read the browser asset {}: {err}\n\
@@ -61,7 +65,7 @@ fn embed_served_asset(name: &str) {
6165
.expect("Unable to write compressed frontend asset");
6266
std::fs::write(
6367
format!("{}.filename.txt", built.display()),
64-
hashed_filename(&built),
68+
hashed_filename(&dist_path(name)),
6569
)
6670
.unwrap();
6771
}

0 commit comments

Comments
 (0)