Skip to content

Commit 73143b2

Browse files
committed
Use cache-busted manifest
1 parent e76e818 commit 73143b2

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static/borders
2727
static/clips
2828
static/videos
2929
static/*.partial.html
30-
static/manifest.json
30+
static/manifest*.json
3131
static/assets
3232
static/contents
3333
static/songs

convert/convertManifest.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { existsSync, readFileSync, writeFileSync } from 'fs';
1+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
22
import path from 'path';
33
import { Task, TaskOutput } from './Task';
4+
import { createHash } from 'crypto';
45

56
export interface ManifestTaskOutput extends TaskOutput {
67
taskName: 'ConvertManifest';
@@ -10,11 +11,12 @@ export interface ManifestTaskOutput extends TaskOutput {
1011
*/
1112
export function convertManifest(dataDir: string, verbose: number) {
1213
const srcFile = path.join(dataDir, 'manifest.json');
13-
const dstFile = path.join('static', 'manifest.json');
14-
if (existsSync(srcFile)) {
14+
let contents = '';
15+
const existing = existsSync(srcFile);
16+
if (existing) {
1517
const fileContents = readFileSync(srcFile).toString();
1618
const lines = fileContents.split('\n');
17-
const updatedFileContents = lines
19+
contents = lines
1820
.map((line) => {
1921
if (line.includes('start_url')) {
2022
const path = process.env.BUILD_BASE_PATH ? process.env.BUILD_BASE_PATH : '.';
@@ -27,8 +29,6 @@ export function convertManifest(dataDir: string, verbose: number) {
2729
return line;
2830
})
2931
.join('\n');
30-
writeFileSync(dstFile, updatedFileContents);
31-
if (verbose) console.log(`converted ${srcFile} to ${dstFile}`);
3232
} else {
3333
// If no manifest exists, we need to at least have a minimum manifest to build.
3434
const manifest = {
@@ -38,8 +38,22 @@ export function convertManifest(dataDir: string, verbose: number) {
3838
background_color: '#000000',
3939
theme_color: '#000000'
4040
};
41-
writeFileSync(dstFile, JSON.stringify(manifest));
41+
contents = JSON.stringify(manifest);
4242
}
43+
44+
const hash = createHash('md5');
45+
hash.update(contents);
46+
const digest = hash.digest('base64url');
47+
48+
const name = `manifest.${digest}.json`;
49+
50+
const dstFile = path.join('static', name);
51+
52+
writeFileSync(dstFile, contents);
53+
if (verbose && existing) console.log(`converted ${srcFile} to ${dstFile}`);
54+
55+
mkdirSync(path.join('src', 'generatedAssets'), { recursive: true });
56+
writeFileSync(path.join('src/generatedAssets', 'manifestUrl.json'), JSON.stringify({ url: name }));
4357
}
4458
export class ConvertManifest extends Task {
4559
public triggerFiles: string[] = ['manifest.json'];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"convert": "ts-node convert/index.ts",
1818
"convert:watch": "ts-node convert/index.ts --watch",
1919
"sandbox": "ts-node data-sandbox/index.ts",
20-
"clean": "rimraf .svelte-kit build src/lib/data/config.js src/lib/data/catalog.js src/lib/data/firebase-config.js src/lib/data/contents.js static/about.partial.html static/assets static/badges static/clips static/collections static/images static/fonts static/styles static/illustrations static/watermarks static/audio static/timings static/videos static/backgrounds static/icons static/borders static/plans static/quiz static/contents static/manifest.json static/data.sqlite static/wasm static/reversal && echo 🔔 Reminder: The project cannot be built until the conversion scripts are run again.",
20+
"clean": "rimraf .svelte-kit build src/generatedAssets /lib/data/config.js src/lib/data/catalog.js src/lib/data/firebase-config.js src/lib/data/contents.js static/about.partial.html static/assets static/badges static/clips static/collections static/images static/fonts static/styles static/illustrations static/watermarks static/audio static/timings static/videos static/backgrounds static/icons static/borders static/plans static/quiz static/contents static/manifest*.json static/data.sqlite static/wasm static/reversal && echo 🔔 Reminder: The project cannot be built until the conversion scripts are run again.",
2121
"clean:data": "rimraf --glob data/*",
2222
"clean:all": "npm run clean && npm run clean:data",
2323
"test": "vitest",

src/app.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="manifest" href="%sveltekit.assets%/manifest.json" />
65
<link rel="stylesheet" type="text/css" href="%sveltekit.assets%/spinner.css" />
76
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
87
%sveltekit.head%

src/routes/+layout.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<!-- app.html (with cache-busting) -->
110110
<link rel="icon" href="{faviconHref}" />
111111
<link rel="apple-touch-icon" href="{appleIconHref}" />
112+
<link rel="manifest" href="{manifestHref.url}" />
112113
<!-- +layout.svelte -->
113114
<meta name="theme-color" content={$s['ui.bar.action']?.['background-color']} />
114115
<link rel="stylesheet" href="{base}/styles/{config.programType.toLowerCase()}-app.css" />

0 commit comments

Comments
 (0)