Javascript 如何在渐进式Web应用程序中在浏览器内存储脱机存储永久数据?
是否可以在浏览器内的脱机存储中存储永久数据? 如果有任何解决方案,那么请帮助我,以便我可以解决我的问题。 我读了一些教程,但那对我没用。Javascript 如何在渐进式Web应用程序中在浏览器内存储脱机存储永久数据?,javascript,jquery,angularjs,reactjs,progressive-web-apps,Javascript,Jquery,Angularjs,Reactjs,Progressive Web Apps,是否可以在浏览器内的脱机存储中存储永久数据? 如果有任何解决方案,那么请帮助我,以便我可以解决我的问题。 我读了一些教程,但那对我没用。 提前谢谢 让我们直截了当地谈谈离线存储数据的一般建议: 对于脱机时加载应用程序所需的网络资源,请使用缓存API(服务人员的一部分) 对于所有其他数据,请使用IndexedDB(带有承诺包装器) 在我告诉您每个浏览器的存储限制之后,我将告诉您如何使用这两种方法 Chrome支持使用让我们直截了当地谈谈离线存储数据的一般建议: 对于脱机时加载应用程序所需的
提前谢谢 让我们直截了当地谈谈离线存储数据的一般建议:
- 对于脱机时加载应用程序所需的网络资源,请使用缓存API(服务人员的一部分)
- 对于所有其他数据,请使用IndexedDB(带有承诺包装器)
- Chrome支持使用让我们直截了当地谈谈离线存储数据的一般建议:
- 对于脱机时加载应用程序所需的网络资源,请使用缓存API(服务人员的一部分)
- 对于所有其他数据,请使用IndexedDB(带有承诺包装器)
- Chrome支持使用您已经阅读过的教程提供的哪种解决方案?此教程中的持久存储为PWAs使用持久存储。这是链接您已经阅读过的教程提供的哪种解决方案?此教程中的持久存储为PWAs使用持久存储。这是链接
var CACHE_VERSION = 1; // Shorthand identifier mapped to specific versioned cache. var CURRENT_CACHES = { font: 'font-cache-v' + CACHE_VERSION }; self.addEventListener('activate', function(event) { var expectedCacheNames = Object.values(CURRENT_CACHES); // Active worker won't be treated as activated until promise // resolves successfully. event.waitUntil( caches.keys().then(function(cacheNames) { return Promise.all( cacheNames.map(function(cacheName) { if (!expectedCacheNames.includes(cacheName)) { console.log('Deleting out of date cache:', cacheName); return caches.delete(cacheName); } }) ); }) ); }); self.addEventListener('fetch', function(event) { console.log('Handling fetch event for', event.request.url); event.respondWith( // Opens Cache objects that start with 'font'. caches.open(CURRENT_CACHES['font']).then(function(cache) { return cache.match(event.request).then(function(response) { if (response) { console.log('Found response in cache:', response); return response; } console.log('Fetching request from the network'); return fetch(event.request).then(function(networkResponse) { cache.put(event.request, networkResponse.clone()); return networkResponse; }); }).catch(function(error) { // Handles exceptions that arise from match() or fetch(). console.error('Error in fetch handler:', error); throw error; }); }) ); });