Skip to content

Commit bb8ed04

Browse files
committed
Avoid stale JavaScript caching
1 parent 1470cc1 commit bb8ed04

File tree

7 files changed

+55
-12
lines changed

7 files changed

+55
-12
lines changed

.github/workflows/deploy.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,22 @@ jobs:
9191
registry: ghcr.io
9292
username: ${{ github.actor }}
9393
password: ${{ secrets.GITHUB_TOKEN }}
94+
- name: Calculcate browser cache key
95+
id: browser-cache-key
96+
uses: mathiasvr/command-output@v2.0.0
97+
with:
98+
run: git rev-parse HEAD:frontend | cut -c 1-4
99+
- name: echo
100+
run: echo ${{ steps.browser-cache-key.outputs.stdout }}
94101
- name: Build and push
95102
uses: docker/build-push-action@v6
96103
with:
97104
push: true
98105
file: ./docker/production/frontend/Dockerfile
99106
tags: ghcr.io/zenmo/zero-frontend:${{ needs.variables.outputs.VERSION_TAG }}
100-
build-args: VITE_ZTOR_URL=https://${{ vars.ZTOR_HOSTNAME || needs.variables.outputs.ZTOR_HOSTNAME }}
107+
build-args: |
108+
VITE_ZTOR_URL=https://${{ vars.ZTOR_HOSTNAME || needs.variables.outputs.ZTOR_HOSTNAME }}
109+
BROWSER_CACHE_KEY=${{ steps.browser-cache-key.outputs.stdout }}
101110
cache-from: type=gha
102111
cache-to: type=gha,mode=max
103112

docker/production/frontend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN --mount=type=cache,target=/home/gradle/.gradle/caches gradle joshi:jsBrowser
99

1010
FROM node:22 AS node
1111
ARG VITE_ZTOR_URL
12+
ARG BROWSER_CACHE_KEY
1213

1314
RUN mkdir -p /app/frontend
1415
RUN mkdir -p /app/build/js/packages

frontend/package-lock.json

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"antd": "^5.11.3",
2727
"bootstrap": "5.3.3",
2828
"jest-environment-jsdom": "^29.6.3",
29-
"joshi": "file:../build/js/packages/zero-joshi",
29+
"joshi": "file:../build/js/packages/zeroweb-joshi",
3030
"leaflet": "^1.9.4",
3131
"lodash": "^4.17.21",
3232
"memoize-immutable": "^3.0.0",
@@ -44,7 +44,7 @@
4444
"react-use-promise": "^0.5.0",
4545
"typescript": "^5.1.6",
4646
"web-vitals": "^2.1.4",
47-
"zero-zummon": "file:../build/js/packages/zero-zummon"
47+
"zero-zummon": "file:../build/js/packages/zeroweb-zummon"
4848
},
4949
"scripts": {
5050
"start": "vite --host 0.0.0.0",

frontend/vite.config.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import {defineConfig} from "vite"
22
import react from "@vitejs/plugin-react"
3+
import {execSync} from "child_process"
4+
5+
// Put hash in file name so that the users don't get stale JS from their browser cache.
6+
let browserCacheKey = process.env.BROWSER_CACHE_KEY
7+
if (!browserCacheKey) {
8+
browserCacheKey = execSync("git rev-parse HEAD:frontend").toString().trim()
9+
.slice(0, 4)
10+
}
311

412
export default defineConfig({
513
plugins: [react({ jsxImportSource: '@emotion/react' })],
@@ -8,12 +16,13 @@ export default defineConfig({
816
port: 3000,
917
},
1018
build: {
11-
minify: false,
19+
// minify: false,
1220
rollupOptions: {
21+
// Tree shaking seems too aggressive on the KotlinJS code
1322
treeshake: false,
1423
output: {
15-
entryFileNames: "[name].js",
16-
assetFileNames: '[name].css',
24+
entryFileNames: `[name].${browserCacheKey}.js`,
25+
assetFileNames: `[name].${browserCacheKey}.css`,
1726
},
1827
},
1928
},

joshi/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ kotlin {
2121
binaries.library()
2222
compilations["main"].packageJson {
2323
// hack hack hack
24-
types = "kotlin/zero-joshi.d.ts"
24+
types = "kotlin/zeroweb-joshi.d.ts"
2525
}
2626
browser {
2727
}

zummon/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kotlin {
2222
binaries.library()
2323
compilations["main"].packageJson {
2424
// hack hack hack
25-
types = "kotlin/zero-zummon.d.ts"
25+
types = "kotlin/zeroweb-zummon.d.ts"
2626
}
2727
browser {
2828
}

0 commit comments

Comments
 (0)