Angular Service Worker在线性能

huangapple go评论81阅读模式
英文:

Angular Service Worker performance for online

问题

根据 Angular 官方文档 https://angular.io/guide/service-worker-intro

Service workers(服务工作者)充当网络代理。它们拦截应用程序发出的所有出站 HTTP 请求,并可以选择如何响应它们。例如,它们可以查询本地缓存,并在有缓存响应可用时提供缓存的响应。代理功能不仅限于通过编程接口(例如 fetch)发出的请求,还包括 HTML 中引用的资源,甚至是对 index.html 的初始请求。因此,基于服务工作者的缓存完全可编程,并不依赖于服务器指定的缓存标头。

根据我从上述内容的理解,它可以用于慢速网络连接或网站离线时。

我想知道是否可以使用“缓存”机制,以便用户在第二次访问时只能看到缓存的页面,而网站仍然在线。如果服务器端数据发生更改,页面应该会更新。我主要是为了应用程序性能而使用它。

大多数示例我找到只提到了慢速网络或离线站点。

我正在使用 Angular 7.2.11

英文:

As per angular official doc https://angular.io/guide/service-worker-intro

> Service workers function as a network proxy. They intercept all
> outgoing HTTP requests made by the application and can choose how to
> respond to them. For example, they can query a local cache and deliver
> a cached response if one is available. Proxying isn't limited to
> requests made through programmatic APIs, such as fetch; it also
> includes resources referenced in HTML and even the initial request to
> index.html. Service worker-based caching is thus completely
> programmable and doesn't rely on server-specified caching headers.

As per my understanding from above, it can be used for slow network connection or when site goes offline.

I want to know if it is possible to avail caching mechanism so that user will only see cached pages when visits second time and site is still online. Pages should be updated if there are changes in server side data. I want to use primarily for app performance.

Most examples I got, it referred only for slow network or offline site.

I am using Angular 7.2.11

答案1

得分: 1

我相信您正在寻找一种渐进式网络应用程序。基本上,您想要将一些数据存储在缓存中,其余的数据存储在浏览器的Web存储中。根据您的应用程序架构、数据大小和要求,您需要决定在何处存储数据以及何时访问它。
请查看以下链接,如果需要进一步的详细信息,请评论:
https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook

英文:

I believe you are looking for a progressive web app. basically you want to store some data in cache and the rest in browser's web storage. depending on architecture of your app, data size and requirements you have to decide where to store the data and when to access it.
have a look at the link below and comment if you need further details Angular Service Worker在线性能
https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook

huangapple
  • 本文由 发表于 2020年1月6日 17:57:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定