You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Service worker responds slowly (10 seconds) when many query parameters are present #3077
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.
Now in the Application tab of DevTools, enable "Bypass for Network" and reload the same URL with many query parameters. Now the response is returned relatively quickly as in the first step.
Originally reported on the WordPress plugin support forum
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.
This is due to the denylist functionality in the service worker's navigation routing:
The following RegExps are each being tested against the long pathname + search:
/^\/wp\-admin($|\?.*|\/.*)/
/[^\?]*.\.php($|\?.*)/
/.*\?(.*&)?(wp_service_worker)=/
/.*\/wp\.serviceworker(\?.*)?$/
/[^\?]*\/feed\/(\w+\/)?$/
/\?(.+&)*wp_customize=/
/\?(.+&)*customize_changeset_uuid=/
/^\/wp\-json\/.*/
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 denylist until you find the one(s) that are expensive, and then attempt to optimize it.
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 denylist, but you want them matched against just the pathname portion of the URL, you could do that pretty easily via a custom matchCallback:
Activity
[-]Service worker responds slowly (1)[/-]westonruter commentedon May 5, 2022
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.
westonruter commentedon May 5, 2022
Actually, I can reproduce the issue on my own site with the latest versions installed.
Service worker URL: https://weston.ruter.net/wp.serviceworker
Workbox version: 6.5.3
jeffposnick commentedon May 5, 2022
This is due to the
denylistfunctionality in the service worker's navigation routing:The following RegExps are each being tested against the long
pathname+search:/^\/wp\-admin($|\?.*|\/.*)//[^\?]*.\.php($|\?.*)//.*\?(.*&)?(wp_service_worker)=//.*\/wp\.serviceworker(\?.*)?$//[^\?]*\/feed\/(\w+\/)?$//\?(.+&)*wp_customize=//\?(.+&)*customize_changeset_uuid=//^\/wp\-json\/.*/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
denylistuntil you find the one(s) that are expensive, and then attempt to optimize it.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.
jeffposnick commentedon May 5, 2022
...one more thing is that if you really need to keep the current set of RegExps in your
denylist, but you want them matched against just thepathnameportion of the URL, you could do that pretty easily via a custommatchCallback: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:
westonruter commentedon May 6, 2022
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.
🙇