From 9494257745ffab1cb2057d012fb33202f3d3423d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 18 Apr 2024 16:49:38 -0600 Subject: [PATCH] Add a bit of jitter --- src/serviceworker/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/serviceworker/index.ts b/src/serviceworker/index.ts index c8456b0b075..5f01a41fc5e 100644 --- a/src/serviceworker/index.ts +++ b/src/serviceworker/index.ts @@ -63,6 +63,9 @@ self.addEventListener("fetch", (event: FetchEvent) => { // Figure out which homeserver we're communicating with const csApi = url.substring(0, url.indexOf("/_matrix/media/v3")); + // Add jitter to reduce request spam, particularly to `/versions` on initial page load + await new Promise(resolve => setTimeout(() => resolve(), Math.random() * 10)); + // Locate our access token, and populate the fetchConfig with the authentication header. // @ts-expect-error - service worker types are not available. See 'fetch' event handler. const client = await self.clients.get(event.clientId);