Javascript 服务人员-chrome mobile,仅在匿名模式下工作

Javascript 服务人员-chrome mobile,仅在匿名模式下工作,javascript,google-chrome,service-worker,Javascript,Google Chrome,Service Worker,我正在尝试使用服务工作者使我的网站脱机工作。 我的软件: var cacheName = 'v40aswedsdfsadg'; var url = "https://spreadsheets.google.com/feeds/list/1LEGGLbrp3hqsN_CyZQMpmrUs5QTajjgjXyCgfwwIDQk/1/public/values?alt=json"; var cacheFiles = [ './', './index.html', './js/a

我正在尝试使用服务工作者使我的网站脱机工作。 我的软件:

var cacheName = 'v40aswedsdfsadg';
var url = "https://spreadsheets.google.com/feeds/list/1LEGGLbrp3hqsN_CyZQMpmrUs5QTajjgjXyCgfwwIDQk/1/public/values?alt=json";
var cacheFiles = [
    './',
    './index.html',
    './js/app.js',
    './css/app.css',
    './vendor/jQuery/dist/jquery.min.js',
    './vendor/angular/angular.min.js',
    './vendor/lodash/dist/lodash.min.js',
    './vendor/gs2json.js',
    url
];

self.addEventListener('install',function(e){
    console.log('[SW] install');
    e.waitUntil(
        caches.open(cacheName).then(function(cache){
            console.log('[SW] add cache');
            return cache.addAll(cacheFiles);
        })
    );
});
self.addEventListener('activate',function(e){
    console.log('[SW] activate');
    e.waitUntil(
        caches.keys().then(function(cacheNames){
            return Promise.all(
                cacheNames.map(function(thisCacheName){
                    if(thisCacheName!==cacheName){
                        console.log('[SW] delete cache: '+thisCacheName+'->'+cacheName);
                        return caches.delete(thisCacheName);
                    }
                }));
        })
    );
});
self.addEventListener('fetch', function(event) {
    console.log('[SW] fetch: '+event.request.url);
    event.respondWith(
        caches.match(event.request)
            .then(function(response) {
                // Cache hit - return response
                if (response) {
                    console.log('[SW] Loaded "'+response.url+'" from cache');
                    return response;
                }
                var fetchRequest = event.request.clone();

                return fetch(fetchRequest).then(
                    function(response) {
                        console.log('[SW] fetch: '+response.url);

                        if(!response || response.status !== 200) {
                            console.log('[SW] fetch failed: ',!response, response.status!==200);
                            alert('fail');
                            return response;
                        }

                        var responseToCache = response.clone();

                        caches.open(cacheName)
                            .then(function(cache) {
                                console.log('[SW] put response to cache');
                                cache.put(event.request, responseToCache);
                            });
                        return response;
                    }
                );
            })
    );
});
使用chrome时效果非常好

它在chrome mobile上不起作用: -我没有得到脱机错误(这意味着服务人员工作) -无法加载来自https的数据 -第一次加载工作正常(从url获取数据时) -第二次和任何下一次加载都不起作用(空白页=未加载数据)

当处于匿名模式(从缓存中获取的数据)时,它在移动chrome上工作

有谁能帮我解决这个问题吗

编辑:
刚刚在移动firefox上测试过,它也能工作。这似乎是移动chrome的问题。

我使用本地存储来保存https响应。其他文件由服务人员保管。现在一切正常。查询其移动chrome错误以修复。