fix: H5热更新缓存击穿+版本比对修复
- fetch URL 加 ?t=Date.now() 缓存击穿 - 版本比对兼容 v0.1.0 vs 0.1.0-dav 前缀差异
This commit is contained in:
@@ -23,11 +23,11 @@ function log(m){document.getElementById('log').innerText+=m+'\n'}
|
|||||||
|
|
||||||
function checkUpdate(){
|
function checkUpdate(){
|
||||||
log('checking '+BASE+'/version.txt ...');
|
log('checking '+BASE+'/version.txt ...');
|
||||||
fetch(BASE+'/version.txt',{cache:'no-store'})
|
fetch(BASE+'/version.txt?t='+Date.now(),{cache:'no-store'})
|
||||||
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||||
.then(t=>{t=t.trim();log('remote: '+t);
|
.then(t=>{t=t.trim();log('remote: '+t);
|
||||||
var local=document.getElementById('ver').innerText;
|
var local=document.getElementById('ver').innerText;
|
||||||
if(t!==local){dlVer=t;dlUrl=BASE+'/h5/index-v7.html';
|
if(t!==local&&t!=='v'+local&&'v'+t!==local){dlVer=t;dlUrl=BASE+'/h5/index-v7.html';
|
||||||
log('*** NEW VERSION: '+dlVer+' ***');document.getElementById('btnApply').disabled=false}
|
log('*** NEW VERSION: '+dlVer+' ***');document.getElementById('btnApply').disabled=false}
|
||||||
else log('up to date')})
|
else log('up to date')})
|
||||||
.catch(e=>log('ERR: '+e.message))
|
.catch(e=>log('ERR: '+e.message))
|
||||||
|
|||||||
Reference in New Issue
Block a user