You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, my website is A(it's static) but it's slow.To improve the speed,I upload all my resources on the website B.And I use ServiceWorker to cache all the resources from B.The next time I need to use them,it will make the request return the cache.And I upload all my pages on B too,so I use ServiceWorker,if I visit a new page in A,ServiceWorker will break the request and pull the page on B.
The code sw.js is like:
//--------------A part of handle-------------------------for(variinblog.origin){if(domain.split(":")[0]==blog.origin[i].split(":")[0]){if(blog.local){returnfetch(req)}setTimeout(async()=>{awaitset_newest_blogver()},30*1000);urls=[]for(letkinblog.plus){urls.push(`https://${blog.plus[k]}`+fullpath(pathname))}for(letkinblog.npmmirror){urls.push(blog.npmmirror[k]+fullpath(pathname))}constgenerate_blog_html=async(res)=>{returnnewResponse(awaitres.arrayBuffer(),{headers: {'Content-Type': 'text/html;charset=utf-8'},status: res.status,statusText: res.statusText})}returnnewPromise((resolve,reject)=>{setTimeout(()=>{caches.match(req).then(function(resp){if(!!resp){cons.s(`Cache Hited! | Origin:${urlStr}`)setTimeout(()=>{resolve(resp)},200);setTimeout(()=>{lfetch(urls,urlStr).then(asyncfunction(res){returncaches.open(CACHE_NAME).then(asyncfunction(cache){cache.delete(req);cons.s(`Cache Updated! | Origin:${urlStr}`)if(fullpath(pathname).match(/\.html$/g)){constNewRes=awaitgenerate_blog_html(res)cache.put(req,NewRes.clone());resolve(NewRes)}else{cache.put(req,res.clone());resolve(res)}});});},0);}else{cons.w(`Cache Missed! | Origin:${urlStr}`)setTimeout(()=>{lfetch(urls,urlStr).then(asyncfunction(res){returncaches.open(CACHE_NAME).then(asyncfunction(cache){if(fullpath(pathname).match(/\.html$/g)){constNewRes=awaitgenerate_blog_html(res)cache.put(req,NewRes.clone());resolve(NewRes)}else{cache.put(req,res.clone());resolve(res)}});}).catch(function(err){resolve(caches.match(newRequest('/offline/index.html')))})},0);setTimeout(()=>{resolve(caches.match(newRequest('/offline/index.html')))},5000);}})},0);})}}//-------------------------------------------------constfullpath=(path)=>{path=path.split('?')[0].split('#')[0]if(path.match(/\/$/)){path+='index'}if(!path.match(/\.[a-zA-Z]+$/)){path+='.html'}returnpath}
I wonder whether I can use pjax if my website has a ServiceWorker like that.
The text was updated successfully, but these errors were encountered:
For example, my website is A(it's static) but it's slow.To improve the speed,I upload all my resources on the website B.And I use ServiceWorker to cache all the resources from B.The next time I need to use them,it will make the request return the cache.And I upload all my pages on B too,so I use ServiceWorker,if I visit a new page in A,ServiceWorker will break the request and pull the page on B.
The code
sw.js
is like:I wonder whether I can use pjax if my website has a ServiceWorker like that.
The text was updated successfully, but these errors were encountered: