Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

fix(engine): version narration URLs by clip length

yzrccef7a1e2d11
diff --git a/engine/engine.js b/engine/engine.js
index 29630e7..f8c4c09 100644
--- a/engine/engine.js
+++ b/engine/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/elementary-algebra/lib/engine.js
+++ b/site/elementary-algebra/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/joke-collection/lib/engine.js b/site/joke-collection/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/joke-collection/lib/engine.js
+++ b/site/joke-collection/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/little-red-riding-hood/lib/engine.js b/site/little-red-riding-hood/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/little-red-riding-hood/lib/engine.js
+++ b/site/little-red-riding-hood/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/math-notebook/lib/engine.js
+++ b/site/math-notebook/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/physics-notebook/lib/engine.js b/site/physics-notebook/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/physics-notebook/lib/engine.js
+++ b/site/physics-notebook/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/science/lib/engine.js b/site/science/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/science/lib/engine.js
+++ b/site/science/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
diff --git a/site/three-little-pigs/lib/engine.js b/site/three-little-pigs/lib/engine.js
index 29630e7..f8c4c09 100644
--- a/site/three-little-pigs/lib/engine.js
+++ b/site/three-little-pigs/lib/engine.js
@@ -1827,7 +1827,9 @@ function start(i, play) {
}
// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
function beatClip(i, take) {
- const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ // the clip's length rides on the URL: regenerated narration gets a new address, so a browser cache cannot pair new
+ // timings with an old clip
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3?v=${TIMINGS[BEATS[i].id]?.dur ?? ''}`;
let a = P.nextClip?._src === src ? P.nextClip : null;
if (!a) {
if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload