BraydenMoore commited on
Commit
52c147a
1 Parent(s): c079e1b

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +27 -12
templates/index.html CHANGED
@@ -283,19 +283,34 @@
283
 
284
  const newUrl = decodeURIComponent("{{ url|safe }}");
285
 
286
- function refreshImage() {
287
- let xhr = new XMLHttpRequest();
288
- xhr.open('HEAD', newUrl + '?t=' + new Date().getTime(), true);
289
- xhr.onreadystatechange = function() {
290
- if (xhr.readyState === 4) {
291
- if (xhr.status === 200) {
292
- if (xhr.getResponseHeader('Content-Type') === 'image/jpeg') {
293
- img.src = newUrl + '&t=' + new Date().getTime();
294
- }
295
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  }
297
- };
298
- xhr.send();
 
299
  }
300
 
301
  const img = new Image();
 
283
 
284
  const newUrl = decodeURIComponent("{{ url|safe }}");
285
 
286
+ //function refreshImage() {
287
+ // let xhr = new XMLHttpRequest();
288
+ // xhr.open('HEAD', newUrl + '?t=' + new Date().getTime(), true);
289
+ // xhr.onreadystatechange = function() {
290
+ // if (xhr.readyState === 4) {
291
+ // if (xhr.status === 200) {
292
+ // if (xhr.getResponseHeader('Content-Type') === 'image/jpeg') {
293
+ // img.src = newUrl + '&t=' + new Date().getTime();
294
+ // }
295
+ // }
296
+ // }
297
+ // };
298
+ // xhr.send();
299
+ //}
300
+
301
+ async function refreshImage() {
302
+ const timestamp = new Date().getTime();
303
+ const fetchUrl = `${newUrl}?t=${timestamp}`;
304
+
305
+ try {
306
+ const response = await fetch(fetchUrl, { method: 'HEAD' });
307
+
308
+ if (response.ok && response.headers.get('Content-Type') === 'image/jpeg') {
309
+ img.src = `${newUrl}&t=${timestamp}`;
310
  }
311
+ } catch (error) {
312
+ console.error('Fetch failed:', error);
313
+ }
314
  }
315
 
316
  const img = new Image();