带有Html5应用程序缓存的Angular 2 [英] Angular 2 with Html5 application cache
本文介绍了带有Html5应用程序缓存的Angular 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有angular 2网站.我想为此网站使用html 5应用程序缓存机制,以为浏览器创建离线应用程序.可能吗?如果可以的话,您可以引导我吗?
I have angular 2 website. I want to use html 5 application cache mechanism for this website to creating offline app for browsers. is it possible? if it is can you guide me.
推荐答案
是的,通过service-worker的概念是可能的,它应该在大多数浏览器中都可以使用.
Yes, It is possible through concept of service-worker, which should work in majority of the browsers.
您可以使用此功能
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
console.log('Service Worker registered');
}).catch(function(err) {
console.log('Service Worker registration failed: ', err);
});
}
</script>
接下来,您需要在index.html中包含服务工作者JS.
Next you need to include service worker JS in index.html.
用于缓存Google维护sw-precache
For caching Google Maintains sw-precache
有用链接 https://github.com/GoogleChrome/sw-precache
https://coryrylan.com/blog/fast-offline-angular-apps-with-service-workers
这篇关于带有Html5应用程序缓存的Angular 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文