一个渐进式Web应用(PWA)需要安装才能离线使用吗?

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

Does a PWA need to be installed to be used offline?

问题

我有一个PWA,例如https://my-pwa.com上提供。用户可以通过将其添加到主屏幕来“安装”此PWA。然后,PWA可以离线使用,因为它使用了一个服务工作程序。

我的问题是,是否有必要进行“添加到主屏幕”的步骤才能使应用离线工作,还是可以在没有进行“添加到主屏幕”的情况下离线使用?

英文:

I have a PWA served e.g. at https://my-pwa.com. Users may "install" this PWA by adding it to their homescreen. The PWA is then available offline as it uses a service worker.

My question is if the "add to homescreen" step is necessary for the app to work offline or if it could be used offline without "add to homescreen"?

答案1

得分: 1

没有要求任何人安装或将PWA添加到主屏幕以使离线功能可用。
正如其他人所说,Service Worker 处理HTTPS请求。如果您在本地缓存了资源,您可以使您的应用程序在离线时工作。
现在,您将需要管理如何处理离线,这可能导致一个相当复杂的应用程序,以处理同步请求以及在离线时提供什么。

英文:

There is no requirement for anyone to install or add a PWA to the homescreen to make offline available.
Like others have stated, the service worker handles HTTPS requests. If you have assets cached locally you can make your application work offline.
Now you will need to manage how you handle offline and this can lead to a reasonably complex application to handle synchronizing requests and what you make available while offline.

答案2

得分: 0

以下是翻译好的部分:

  • 问题有点不太清楚。
  • 但我猜你打算在没有WiFi连接的情况下本地使用你的PWA。
  • 是的,这是可能的。实际上,如果你的IDE打开并且所有模块都已安装,你甚至可以在没有互联网连接的情况下进行开发。
  • 我猜你使用类似Ionic的框架。假设我从git克隆了你的项目并将文件存储在本地:
    1. 我会在我的IDE中打开项目。
    2. 大多数现代IDE会扫描package.json。当你在开发过程中通过npm安装模块时,它们会被添加为依赖项。它们会询问你是否要安装这些模块。或者你可以输入npm install 命令,它会从互联网获取这些模块。
    3. 如果有额外的依赖项需要安装,你需要手动安装它们(不是通过npm i)。
    4. 只要PWA本身不需要WiFi连接,你就可以在本地运行你的项目,不需要WiFi连接。

根据你使用的框架,你现在可以运行应用程序(对于Angular,使用ng serve 或者对于Ionic,使用ionic --serve等)。你还可以在本地运行服务器,让它们进行通信。不需要WiFi连接。

安装并不是一件简单的事情,至少需要一些关于使用IDE的知识。简单的“添加到主屏幕”操作是无法帮助的。我认为网站被缓存,所以可以离线使用。如果你清除了缓存,网站应该会出现问题。

英文:

The question is a bit unclear.

But I assume you intend to use your PWA locally without a WiFi-connection.

And yes that is possible. You actually can also work on it without being connected to the internet if you just have your IDE open and all the modules installed.

And that's the point. I assume you use a framework like ionic. Let's say I'd clone your project from git and have the files stored locally:

  1. I would open the project in my IDE.
  2. Most modern IDEs scan the package.json. When you install a module via npm while developing it will be added as a dependancy. They ask you if you want to install the modules. Alternatively you can type npm install and it will get the modules from the internet.
  3. If you have extra dependencies that need to be installed, you'd have to do so. (not via npm i)
  4. You can now run your project locally without a WiFi connection AS LONG as the PWA itself doesn't need WiFi.

Depending on your framework you can now run the app (with Angular by ng serve or ng build for ionic with ionic --serve etc). You could also run a server locally and let them communicate together. No WiFi needed.

Installing is not trivial and requires at least some knowledge about using IDEs. A simple: "Add to homescreen" would not help. I think the website is cached on so works offline. If you'd clear that cache the website should break.

答案3

得分: 0

根据我自己和@Pieterjan进行的测试,结果表明即使没有明确添加到用户的主屏幕,PWA仍然可以在离线状态下访问。

也就是说,用户访问https://my-pwa.com后,稍后可以在相同的浏览器中在没有互联网连接的情况下再次访问https://my-pwa.com。不需要"添加到主屏幕"。

英文:

Based on testing performed by myself and @Pieterjan it turns out that PWAs are indeed accessible offline even when not explicitly added to the user's homescreen.

I.e. a user visiting https://my-pwa.com can later re-visit https://my-pwa.com in the same browser without an internet connection. No "add to homescreen" required.

huangapple
  • 本文由 发表于 2023年2月26日 19:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75571808.html
匿名

发表评论

匿名网友

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

确定