简体   繁体   English

如何使 Service Worker 与通配符子域兼容?

[英]How Do I Make a Service Worker Compatible with Wildcard Subdomains?

I have a fairly simple question.我有一个相当简单的问题。 I have a manifest.json file for my new service worker that lists "start_url" as "https://example.com" and the scope is "/".我的新服务工作者有一个 manifest.json 文件,其中将“start_url”列为“https://example.com”,范围为“/”。 That works great unless the URL has a subdomain.除非 URL 有子域,否则效果很好。 In that case I get several errors saying that the manifest start url is not valid, it has been ignored, and that the manifest has no matching service worker.在这种情况下,我收到几个错误,指出清单起始 url 无效,它已被忽略,并且清单没有匹配的 Service Worker。

The service worker still works but I would like to eliminate these errors. Service Worker 仍然有效,但我想消除这些错误。 I use wildcard subdomains for all listings categorized by geographic location (ex: https://city-state.example.com ).我对按地理位置分类的所有列表使用通配符子域(例如: https : //city-state.example.com )。 That lets me feather out the categories on the other side of the domain name (ex: https://city-state.example.com/category/subcategory ).这让我可以区分域名另一侧的类别(例如: https : //city-state.example.com/category/subcategory )。 Is there a way to use something like https://(*).example.com for the start url or scope to avoid this error?有没有办法使用 https://(*).example.com 之类的内容作为起始 url 或范围来避免此错误?

A service worker is scoped to a single origin and no higher in a file page than the level it is served from. Service Worker 的范围仅限于单个源,并且在文件页面中的级别不高于它所提供的级别。 The rules are to provide security and prevent 3rd party scripts from attaching service workers to invade your site.这些规则是为了提供安全性并防止 3rd 方脚本附加服务人员来入侵您的站点。

You will have to replicate your service worker on each origin.您必须在每个源上复制您的 Service Worker。 But honestly, unless the application is exactly the same you will want to customize the service worker logic to the specific application.但老实说,除非应用程序完全相同,否则您将希望针对特定应用程序自定义 Service Worker 逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM