question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service worker responds slowly (10 seconds) when many query parameters are present

See original GitHub issue

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:

  1. Go to https://www.sensorsone.com/ and let the service worker install
  2. Try reloading the page and see it only takes a couple seconds.
  3. Now try going to the same URL with many query parameters, and notice that the response from the service worker takes over 10 seconds.
  4. 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffposnickcommented, May 5, 2022

This is due to the denylist functionality in the service worker’s navigation routing:

Screen Shot 2022-05-05 at 4 42 38 PM

The following RegExps are each being tested against the long pathname + search:

  1. /^\/wp\-admin($|\?.*|\/.*)/
  2. /[^\?]*.\.php($|\?.*)/
  3. /.*\?(.*&)?(wp_service_worker)=/
  4. /.*\/wp\.serviceworker(\?.*)?$/
  5. /[^\?]*\/feed\/(\w+\/)?$/
  6. /\?(.+&)*wp_customize=/
  7. /\?(.+&)*customize_changeset_uuid=/
  8. /^\/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.

0reactions
westonrutercommented, May 6, 2022

Thanks a lot! I was able to identify these two patterns as causing the expensive backtracing:

/\?(.+&)*wp_customize=/
/\?(.+&)*customize_changeset_uuid=/

I’m going to optimize those and then consider your improved denial logic for the future.

🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Long URL with many query parameters slowing loading
Hi, I'm finding the PWA plugin is slowing the loading of long URL with many query parameters ~30. The length of one I...
Read more >
Service Worker slow response times - google chrome
In the project we have here, there are static resources served with high cache expirations set, and we use query parameters (repository revision ......
Read more >
Troubleshoot slow SQL Server performance caused by I/O ...
Provides a methodology to isolate and troubleshoot SQL performance problems caused by slow disk I/O.
Read more >
Service worker configuration - Angular
This topic describes the properties of the service worker configuration file. ... Therefore, the patterns will partially match the request URLs.
Read more >
Any way to speed up really slow refresh times in Power Query?
Another site said to enable the Fast Data Load under Query Options. I've done that, but it doesn't seem to help much. Is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found