Ignore only-if-cached cache mode on Mozilla Firefox prior to version 60 (#7503)
This commit is contained in:
		
							parent
							
								
									ff84c18e3d
								
							
						
					
					
						commit
						918cfd3be6
					
				
					 1 changed files with 10 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -13,6 +13,8 @@ function fetchRoot() {
 | 
			
		|||
  return fetch('/', { credentials: 'include' });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const invalidOnlyIfCached = navigator.userAgent.match(/Firefox\/(\d+)/)[1] < 60;
 | 
			
		||||
 | 
			
		||||
// Cause a new version of a registered Service Worker to replace an existing one
 | 
			
		||||
// that is already installed, and replace the currently active worker on open pages.
 | 
			
		||||
self.addEventListener('install', function(event) {
 | 
			
		||||
| 
						 | 
				
			
			@ -54,19 +56,22 @@ self.addEventListener('fetch', function(event) {
 | 
			
		|||
    event.respondWith(openSystemCache().then(cache => {
 | 
			
		||||
      return cache.match(event.request.url).then(cached => {
 | 
			
		||||
        if (cached === undefined) {
 | 
			
		||||
          return fetch(event.request).then(fetched => {
 | 
			
		||||
            if (fetched.ok) {
 | 
			
		||||
              const put = cache.put(event.request.url, fetched.clone());
 | 
			
		||||
          const asyncResponse = invalidOnlyIfCached && event.request.cache === 'only-if-cached' ?
 | 
			
		||||
            fetch(event.request, { cache: 'no-cache' }) : fetch(event.request);
 | 
			
		||||
 | 
			
		||||
          return asyncResponse.then(response => {
 | 
			
		||||
            if (response.ok) {
 | 
			
		||||
              const put = cache.put(event.request.url, response.clone());
 | 
			
		||||
 | 
			
		||||
              put.catch(() => freeStorage());
 | 
			
		||||
 | 
			
		||||
              return put.then(() => {
 | 
			
		||||
                freeStorage();
 | 
			
		||||
                return fetched;
 | 
			
		||||
                return response;
 | 
			
		||||
              });
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return fetched;
 | 
			
		||||
            return response;
 | 
			
		||||
          });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue