Skip to content

Commit 575dfc8

Browse files
committed
fix ios cache busting on preview fix
1 parent 06dc29b commit 575dfc8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

assets/js/preview.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
/* eslint n/no-unsupported-features/node-builtins: "off" */
22
/* globals photoBooth photoboothTools */
3+
4+
function addCacheBustingParam() {
5+
const url = getBasePreviewUrl();
6+
const timestamp = new Date().getTime();
7+
8+
if (url.includes('?')) {
9+
return `${url}&t=${timestamp}`;
10+
}
11+
12+
return `${url}?t=${timestamp}`;
13+
}
14+
15+
function getBasePreviewUrl() {
16+
if (!config.preview || !config.preview.url) {
17+
return '';
18+
}
19+
20+
const raw = config.preview.url;
21+
const match = raw.match(/^url\((['"]?)(.+?)\1\)$/);
22+
23+
return match ? match[2] : raw;
24+
}
25+
326
const photoboothPreview = (function () {
427
// vars
528
const CameraDisplayMode = {
@@ -179,6 +202,7 @@ const photoboothPreview = (function () {
179202
} else if (config.preview.mode === PreviewMode.URL.valueOf()) {
180203
photoboothTools.console.logDev('Preview: Preview at countdown from URL.');
181204
setTimeout(function () {
205+
url.css('background-image', 'url("' + addCacheBustingParam() + '")');
182206
url.show();
183207
url.addClass('streaming');
184208
}, config.preview.url_delay);
@@ -191,6 +215,7 @@ const photoboothPreview = (function () {
191215
} else if (config.preview.mode === PreviewMode.URL.valueOf()) {
192216
photoboothTools.console.logDev('Preview: Preview from URL.');
193217
setTimeout(function () {
218+
url.css('background-image', 'url("' + addCacheBustingParam() + '")');
194219
url.show();
195220
url.addClass('streaming');
196221
}, config.preview.url_delay);
@@ -220,6 +245,7 @@ const photoboothPreview = (function () {
220245
}
221246
url.removeClass('streaming');
222247
url.hide();
248+
url.css('background-image', 'none');
223249
video.hide();
224250
pictureFrame.hide();
225251
collageFrame.hide();

0 commit comments

Comments
 (0)