Implementing production services with appcache backup for unsupported browsers

I am learning how to create a progressive web application in Aurelia with stand-alone functionality that works in all major browsers. Service workers appear to be the preferred option for asset caching, but with no support in Safari (and currently Edge). Can service workers with backup access to appcache be used if they are not supported? What will the application look like if there is an appcache manifest and is the working service installed?

+5
source share
4 answers

if the browser supports work services, then caching of the service worker will be used instead of the appCache manifest. You can enable the appCache manifest for legacy browsers like Safari, and everything will work as they did in the past. In addition, for modern browsers, they will use the caching of service workers and act as if the application did not exist. It looks like reacting images work.

+4
source

Testing the technology supported by the browser is easy:

if(navigator.serviceWorker){
    initServiceWorker()
}else if(window.applicationCache){
    initApplicationCache();
}else{
    console.log('no caching possible');
}

Dynamically loading a service worker should not be a problem, as it is done in javascript anyway.

applicationCache mainfest , iframe: HTML5?

+2

. , - .

WKWebView

0

2019 iPhone WebViews. , .

, , . , . , .

The trick I am doing now to disable the application cache when a service is running intercepts the html request (navigation) and simply removes the attribute manifestfrom <html>.

Something like this in a working service script:

self.addEventListener('fetch', (ev) => {
  if (request.mode === 'navigate' && request.method === 'GET') {
    ev.respondWith(
      fetch(ev.request.url)
        .then(r => r.text())
        .then(html => new Response(html.replace('manifest=', 'xmanifest='), {
          headers: {'Content-Type': 'text/html'}
        }))
    )
  }
})
0
source

Source: https://habr.com/ru/post/1679354/


All Articles