【问题标题】:Cache persistance in PWA in iOSiOS 中 PWA 中的缓存持久性
【发布时间】:2021-10-20 21:28:21
【问题描述】:

拥有一个可以与网络连接正常工作的 PWA。添加了一个服务工作者,如果 PWA 在网络连接丢失之前的某个时间点打开,它可以在没有连接的情况下工作。到目前为止,一切顺利。

如果我强制 PWA(在 iPhone 上向上滑动)然后尝试 PWA,它是空白的并要求网络连接。这正常吗?强制退出应用程序是否会清除缓存的文件?还是我错过了什么?

Service Worker 代码:

    var cacheName = 'floorwork';
    var filesToCache = [
    '/',
    '/index.html',
    '/themes/basicblue.min.css',
    '/themes/jquery.mobile.icons.min.css',
    '/images/carltonsig.png',
    '/images/claw1.jpg',
    '/images/GLSeal.jpg',
    '/js/jquery-1.11.1.js',
    '/js/jquery.mobile-1.4.5.min.js'
    ]; 

    self.addEventListener('install', function(e) {
    e.waitUntil(
    caches.open(cacheName).then(function(cache) {
    return cache.addAll(filesToCache);
    })
    );
    });  

    self.addEventListener('fetch', function(e) {
    e.respondWith(
    caches.match(e.request).then(function(response) {
    return response || fetch(e.request);
    })
    );
    });
   

【问题讨论】:

    标签: caching jquery-mobile progressive-web-apps offline-caching


    【解决方案1】:

    我正在使用以下代码来持久化数据:

    navigator.storage.persist().then(function(persistent) {
                    if (persistent)
                        console.log("Storage will not be cleared except by explicit user action");
                    else
                        console.log("Storage may be cleared by the UA under storage pressure.");
                });

    关闭应用程序并重新打开后一切似乎都很好,但是根据我刚刚提出的其他问题(我还没有答案),如果我关闭手机并重新打开,我的 PWA 缓存有问题在访问应用程序之前将手机调至飞行模式。所以我想我的回答可能会解决您的部分问题,但可能无法解决所有问题。

    【讨论】:

    • 感谢您的信息,我会试试看!
    猜你喜欢
    • 1970-01-01
    • 2022-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 2020-09-26
    • 2012-09-09
    • 1970-01-01
    相关资源
    最近更新 更多