gpt4 book ai didi

javascript - React JS 中的 service worker 是什么

转载 作者:IT王子 更新时间:2023-10-29 03:01:12 24 4
gpt4 key购买 nike

在创建 React 应用程序时,默认情况下会调用 Service Worker。为什么使用 Service Worker?默认调用的原因是什么?

最佳答案

您的应用程序可能不需要服务 worker 。如果您使用 create-react-app 创建一个项目,它会被默认调用

Service workers 在 article 中得到了很好的解释 。从中总结

A service worker is a script that your browser runs in thebackground, separate from a web page, opening the door to featuresthat don't need a web page or user interaction. Today, they alreadyinclude features like push notifications and background sync and haveability to intercept and handle network requests, includingprogrammatically managing a cache of responses.

In the future, service workers might support other things likeperiodic sync or geofencing.

根据这个 PR to create-react-app

Service workers are introduced with create-react-app viaSWPrecacheWebpackPlugin.

Using a server worker with a cache-first strategy offers performanceadvantages, since the network is no longer a bottleneck for fulfillingnavigation requests. It does mean, however, that developers (andusers) will only see deployed updates on the "N+1"visit to a page, since previously cached resources are updated in thebackground.

在新应用中默认启用对register service worker 的调用,但您可以随时将其删除,然后恢复正常行为。

关于javascript - React JS 中的 service worker 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49314386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com