Skip to content

Commit f1e9308

Browse files
committed
fix(demo): cache-bust vocab JS + defensive fallback when loadFromFlatFreq missing
Yesterday's switch to the APK dict required a new SwipeVocabulary.loadFromFlatFreq method. Fastly/Cloudflare and the browser both cache swipe-vocabulary.js for 4 h (max-age=14400), so users who had /demo/ open — or who hit the edge cache before it invalidated — got a stale JS without the new method, producing "swipeVocabulary.loadFromFlatFreq is not a function" on load. Two defenses: - Version-query the demo's three support scripts (swipe-vocabulary, custom-dictionary, niche-words-loader). Future JS changes bump the `?v=` token, forcing both the CDN and the browser to fetch fresh. - In loadVocabulary(), typeof-check the method before calling it; if an ancient cached version is somehow still loaded, silently fall back to loadFromJSON (the 150k vocab) instead of hard-failing. — opus 4.7
1 parent 58df5d5 commit f1e9308

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

web_demo/demo/index.html

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
<!-- ONNX Runtime Web -->
99
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.18.0/dist/ort.min.js"></script>
1010
<!-- Swipe Vocabulary Module -->
11-
<script src="swipe-vocabulary.js"></script>
11+
<!-- ?v=<hash> cache-busts Cloudflare/Fastly edge + browser cache so users
12+
don't get stranded on an old JS that predates loadFromFlatFreq et al. -->
13+
<script src="swipe-vocabulary.js?v=20260419b"></script>
1214
<!-- Custom Dictionary Support -->
13-
<script src="custom-dictionary.js"></script>
15+
<script src="custom-dictionary.js?v=20260419b"></script>
1416
<!-- Niche Words Loader -->
15-
<script src="niche-words-loader.js"></script>
17+
<script src="niche-words-loader.js?v=20260419b"></script>
1618
<script>
1719
tailwind.config = {
1820
theme: {
@@ -730,7 +732,15 @@ <h3 class="text-lg font-semibold text-white mb-3">Dictionary Statistics</h3>
730732
swipeVocabulary = new SwipeVocabulary();
731733
let loaded = false;
732734

733-
if (DEMO_CONFIG.dictionary === 'apk') {
735+
// Defensive: an old cached swipe-vocabulary.js may predate
736+
// loadFromFlatFreq. If the method is missing, skip straight
737+
// to the 150k JSON loader instead of hard-failing.
738+
const canLoadFlat = typeof swipeVocabulary.loadFromFlatFreq === 'function';
739+
if (!canLoadFlat) {
740+
console.warn('swipe-vocabulary.js is stale (no loadFromFlatFreq); falling back to full 150k vocab');
741+
}
742+
743+
if (DEMO_CONFIG.dictionary === 'apk' && canLoadFlat) {
734744
updateLoadingStatus('Loading APK dictionary (52k, ~930KB)...');
735745
loaded = await swipeVocabulary.loadFromFlatFreq('en_enhanced.json');
736746
if (!loaded) {

0 commit comments

Comments
 (0)