- sw.js + manifest.json: cache-first service worker for instant repeat-visit loads and full offline use. Registered only when window.CHESS_PWA is true. - Disabled by default: an active SW serves returning visitors from cache, so they'd stop hitting the server and disappear from the Fly logs. Enable at build time with --build-arg ENABLE_CHESS_PWA=1 (Dockerfile flips the flag); ENABLE_CHESS_PWA=1 make dev does the same locally. - scripts/bump_version.sh + 'make bump': bump the asset cache version across index.html (?v=N) and sw.js (CACHE) in sync. Required before deploy so the service worker / browser cache pick up changed assets. Bumped v25 -> v26. - README: document cache versioning + PWA flag.
32 lines
1.2 KiB
Bash
Executable File
32 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Bump the static-asset cache-bust version in one shot.
|
|
#
|
|
# The version appears in two places that must stay in sync:
|
|
# - index.html -> style.css?v=N and app.js?v=N (browser HTTP cache)
|
|
# - sw.js -> CACHE = "chess-pressure-vN" (service worker cache, PWA)
|
|
#
|
|
# Run this whenever you change app.js / style.css (or any cached asset) so
|
|
# returning visitors pick up the new files instead of a stale cached copy.
|
|
# This matters always for the browser cache, and is *critical* when the PWA
|
|
# service worker is enabled (ENABLE_CHESS_PWA=1) — without a bump the SW keeps
|
|
# serving the old assets forever.
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
STATIC="src/chess_pressure/static"
|
|
INDEX="$STATIC/index.html"
|
|
SW="$STATIC/sw.js"
|
|
|
|
cur=$(grep -oE '\?v=[0-9]+' "$INDEX" | head -1 | grep -oE '[0-9]+' || true)
|
|
if [ -z "${cur:-}" ]; then
|
|
echo "error: could not find a '?v=N' version in $INDEX" >&2
|
|
exit 1
|
|
fi
|
|
next=$((cur + 1))
|
|
|
|
sed -i -E "s/\?v=$cur\b/?v=$next/g" "$INDEX"
|
|
sed -i -E "s/chess-pressure-v$cur\b/chess-pressure-v$next/g" "$SW"
|
|
|
|
echo "cache version bumped: v$cur -> v$next"
|
|
grep -nE '\?v=[0-9]+|chess-pressure-v[0-9]+' "$INDEX" "$SW" | sed 's/^/ /'
|