[英]How to store offline Storage permanent data inside browser in Progressive Web Apps?
Is it Possible to store permanent data in offline Storage inside browser? 是否可以在浏览器内部的离线存储中存储永久数据? If any solution is there then help me so that i can solve my problem.
如果有任何解决方案,那么请帮助我,以便我可以解决我的问题。 I read Some Tutorial but that is not useful me .
我阅读了一些教程,但这对我没有用。 Thanks in Advance!
提前致谢!
Let's get right to the point with a general recommendation for storing data offline: 让我们直接提出离线存储数据的一般建议:
I'll tell you how to use both after i tell you the storage limits per browser. 在告诉您每个浏览器的存储限制后,我将告诉您如何使用两者。
A working example of a service worker using the cache api is 使用缓存API的服务工作者的工作示例是
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;
});
})
);
});
[Source and Explanation] [来源和说明]
And i'm not sure about how to use IndexedDB Some other ways are 我不确定如何使用IndexedDB其他一些方法是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.