How to manage request queue in browser

Evgeniy Saenko
2 min readMay 26, 2021

--

Image from MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x

Motivation

Currently HTTP/1.X is commonly used protocol in browser-server connections, and browser restrictions can cause some problems, such as queueing our requests while there is some (4–6) request in progress. And in most cases not all of this requests are necessary or important, some of this requests more valuable then others and we need process them with a higher priority.

So, here we comes to concurrency request pool. To be honest, i know about HTTP/2, domain splitting and other way to resolve this situation, but why can’t there be another one?

About browser queueing

Basically browser will open up to 6 connection to each domain for our request (you can see more about that on MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Connection_management_in_HTTP_1.x). The next requests will be queued and wait for free connection when one of existed request completes successfully. This can produce behavior when important state updating request is stuck in queue while some minor data requests is taking too much time.

Creating our own queue

In case when we can’t create different domain or swap to HTTP/2 for our application, we can resolve this problem by creating our own request queue and manage every single request. Full source code you can see in my github: https://github.com/essaenko/concurrent-request-pool.

Simple usage

Here we create request pool with default settings, by pass limit property to the constructor we can manage how much concurrent connections will be used. If you want manage your connections by some sorting, you can create channels and pass request to different channels.

Full documentation you can read here: https://github.com/essaenko/concurrent-request-pool#typescript-based-pool-of-concurrent-requests

Summary

In most cases developers will resolve browser queue limitation by other way like different domain for unimportant requests or swapping to HTTP/2. But when you’ll fall in situation when you will need avoid this limitations only with JavaScript, request pool can be the simplest way)

Thanks you for reading and i’ll be appreciate for your comments.

--

--

Evgeniy Saenko
Evgeniy Saenko

Written by Evgeniy Saenko

I’m experienced frontend developer specialized on building fault-tolerant interfaces, offline-first applications, PWA and other.

No responses yet