refactor: asset caching via query param (#192)

This updates the asset caching to use a cache busting query string,
rather than a totally separate path. This makes it safer to apply
caching automatically to things like `<img>` tags, as the path does not
change anymore.
This commit is contained in:
Luca Casonato
2022-05-16 17:39:22 +00:00
committed by GitHub
parent c28d2ff863
commit cf438a7879
6 changed files with 56 additions and 24 deletions
+19
View File
@@ -0,0 +1,19 @@
import { assertEquals } from "../../tests/deps.ts";
import { asset } from "./utils.ts";
globalThis.__FRSH_BUILD_ID = "ID123";
Deno.test("asset", () => {
assertEquals(asset("/test.png"), "/test.png?__frsh_c=ID123");
assertEquals(asset("/test?f=1"), "/test?f=1&__frsh_c=ID123");
assertEquals(asset("/test#foo"), "/test?__frsh_c=ID123#foo");
assertEquals(asset("/test?f=1#foo"), "/test?f=1&__frsh_c=ID123#foo");
assertEquals(asset("./test.png"), "./test.png");
assertEquals(asset("//example.com/logo.png"), "//example.com/logo.png");
assertEquals(asset("/test.png?__frsh_c=1"), "/test.png?__frsh_c=1");
assertEquals(
asset("https://example.com/logo.png"),
"https://example.com/logo.png",
);
});