Skip to content

Commit

Permalink
Add a bit of jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Apr 18, 2024
1 parent af1ba39 commit 9494257
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/serviceworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(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);
Expand Down

0 comments on commit 9494257

Please sign in to comment.