-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service worker responds slowly (10 seconds) when many query parameters are present #3077
Comments
I just saw that the user was running PWA plugin v0.6 which included Workbox v5. I'm asking them to update to v0.7 which includes the current Workbox version to see if that fixes the issue. |
Actually, I can reproduce the issue on my own site with the latest versions installed.
Service worker URL: https://weston.ruter.net/wp.serviceworker |
This is due to the The following RegExps are each being tested against the long
I can't tell you offhand which one of them is giving you particularly bad performance when tested against that long input, but it normally tends to be a RegExp that does a bunch of backtracking. You could try removing them one by one from your I'm going to close this issue, since it appears to be more about how Workbox is configured than about the core functionality. Let me know if there's anything else I can do to assist, though. |
...one more thing is that if you really need to keep the current set of RegExps in your const denylist = [/.../, /.../];
const navigationMatcher = ({request, url}) => {
if (request.mode !== 'navigate') {
return false;
}
for const (regexp of denylist) {
if (regexp.test(url.pathname)) {
return false;
}
}
return true;
};
registerRoute(
navigationMatcher,
SomeStrategy(),
); This would help if you know that it's unlikely for folks to have a very long path, while it's more likely for them to have a lot of query parameters. You could also get more fine-grained to how you match your path segments while avoiding RegExps if you need to: const skipIfSegmentMatches = ['skip1', 'skip2'];
const navigationMatcher = ({request, url}) => {
if (request.mode !== 'navigate') {
return false;
}
const segments = url.pathname.split('/');
for const (segment of skipIfSegmentMatches) {
if (segments.includes(segment)) {
return false;
}
}
return true;
};
registerRoute(
navigationMatcher,
SomeStrategy(),
); |
Thanks a lot! I was able to identify these two patterns as causing the expensive backtracing:
I'm going to optimize those and then consider your improved denial logic for the future. 🙇 |
Library Affected:
workbox-strategies
Browser & Platform:
Google Chrome v101.0.4951.41
Issue or Feature Request Description:
On a site using the PWA plugin for WordPress, which includes Workbox, the service worker is taking 10 seconds for the NetworkFirst strategy to respond to requests for URLs that have many query parameters.
Steps to reproduce:
Originally reported on the WordPress plugin support forum
The text was updated successfully, but these errors were encountered: