Understand Service Worker scope matching constraints
mainWhen using URLPattern for Service Worker scopes, there are specific design constraints to ensure performance and security:
- Non-variable prefix: Scopes must have a non-variable prefix (e.g.,
/foo/*). This allows the browser to quickly exclude unrelated origins. - Complexity limits: To prevent performance abuse, registrations that result in too many nested, non-greedy scope patterns (e.g., more than 10) may be rejected.
- Restricted syntax: Service worker scopes are restricted to exact matches and trailing wildcards. More complex regular expression groups are not supported for scopes to avoid unpredictable performance.
- Ordering: Scopes are matched from most specific to least specific. For example,
/foo/is more specific than/foo/*, which is more specific than/foo/*?.