最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Are Service Workers necessary for a Progressive Web Application? - Stack Overflow

programmeradmin2浏览0评论

Service workers are not supported by all browsers; caniuse estimates that they would work for approximately 85% of users.

If i built a PWA, does it need to use service workers?

Service workers are not supported by all browsers; caniuse estimates that they would work for approximately 85% of users.

If i built a PWA, does it need to use service workers?

Share Improve this question edited Dec 3, 2018 at 13:11 OliverRadini 6,4761 gold badge25 silver badges56 bronze badges asked Dec 3, 2018 at 13:04 simplastsimplast 1091 silver badge3 bronze badges 6
  • 2 Progressive web apps are not defined by a rigid, strict standard, but instead by a set of guidelines. These guidelines sometimes outline specific technologies; for instance Site is served over HTTPS, others All app URLs load while offline are simply remendations for the behaviour of the app. Have you looked at the PWA checklist? developers.google./web/progressive-web-apps/checklist – OliverRadini Commented Dec 3, 2018 at 13:09
  • as far as i know, and i am not expert for pwa, service worked manages caching so your app can work offline. You probably can make pwa without it but then it is not really pwa. there is pacage for vue that makes your app pwa. Try it without service worker and go to chrome dev tools and go to audits and run check to see – curious lad Commented Dec 3, 2018 at 13:10
  • thank you so much! i will learn more about Progressive web apps and find out what's the real problem that i will meet. – simplast Commented Dec 3, 2018 at 13:23
  • 85% is very high. You might run across appcache, the previous way to achieve offline cached applications, but even that is only at 93% of users. With service workers, you really only have to worry about IE 11 and earlier, and users that never upgrade. – William Walseth Commented Dec 3, 2018 at 14:59
  • 1 It should be optional but Chrome and oppressive Lighthouse demand you not only have a SW but it is used for caching or you won't get the ask-to-install functionality :-( – McMurphy Commented Dec 4, 2018 at 1:06
 |  Show 1 more ment

2 Answers 2

Reset to default 2

This will depend on the browser, but if you want your PWA to be installable, most browsers require that there is a service worker which has a fetch handler.

https://web.dev/install-criteria/#criteria

Referring to Chrome:

Registers a service worker with a fetch handler

It also says:

Other browsers have similar criteria for installation, though there may be minor differences.

In my experience service workers aren't mandatory to deliver a PWA with offline functionality.

As long as your PWA pages are properly marked as cacheable you can run your PWA pletely offline and it won't need a connection to your server if the lifetime of the page is in the browsers cache lifetime. The "Create Shortcut" functionality of Chrome is driven by the webmanifest and not by the fact that it uses a service worker. You can create a desktop shortcut for a page if it has a manifest.

You can furthermore do an AJAX call to a URL which is definitively not cached to figure out if you are running off-line or online and update your page if the 'update' URL tells you to do so by using location.reload()

Update: Chrome and MS Edge require a service worker controlling the page in order to provide an "install" button for the PWA in the address bar.

,

see also here Progressive web app not showing install button in browser bar

The required service worker however can be pretty basic and make use of the browser built-in caches: no need to employ service worker caches.
To get a better overview how that works in practice I created a small github project visible at https://github./leopatras/simple_offline_pwa.

The page can be checked live at https://www.generomobile.de/gmi/simple_offline_pwa/test.html

发布评论

评论列表(0)

  1. 暂无评论