Enable Keep Alive

July 03, 2020 | 04 min read

1. Overview

Let’s discuss some basics that help you in an easy understanding of the concept of Keep Alive. First, get to know about what is meant by the TCP and HTTP at the beginning.
The Transmission Control Protocol (TCP) is one of the main protocols of the Internet protocol suite. It defines how to establish and maintain a network conversation through which application programs can exchange data. TCP works with the Internet Protocol (IP), which defines how computers send packets of data to each other.
HTTP: HyperText Transfer protocol. HTTP is an application protocol used for data communication. It is the base of data communication in the World Wide Web. It provides a standard for web browsers that facilitates users to exchange information over the internet.
The default HTTP connection is usually closed after each request has been completed, meaning that the server closes the TCP connection after delivering the response. In order to keep the connection open for multiple requests, the keep-alive connection is utilized.

2. What exactly is Keep-Alive?

Keep-alive is a method to allow the same TCP connection for HTTP conversation instead of opening a new connection with each new request. It is also a communication between the server and the browser with the potential to absolutely reduce the number of requests and helps in the quick loading of a web page.
More simply put, it is a communication between the web server and the web browser that says “you can grab more than just one file at a time”.
Keep-alive is also known as a Persistent Connection.
Technically, a single TCP connection is used to send and receive multiple HTTP requests. So this would reduce the network latency.

3. Why do you need Keep-Alive?

Creating multiple connections can extend the loading time of your webpage. Connections also utilize many resources on the server. We can eventually overcome this issue and transfer all files by operating a single connection.
Keep-alive are extremely small messages that consume very little bandwidth. Enabling keep-alive depends on what server you are using and what you have access to.
Keep-alive reduces the latency of continuous requests. It also boosts the speed and performance of the loading of a webpage on your site.

4. How to minimize Javascript files?

Refer to the pictorial representation of how the files are delivered from the server when requested from the users.
  • By not applying Keep-Alive
If Keep-alive is not applied, communication with the server gets started for every requested file and thus allow unnecessary multiple connections.
This process could take considerably longer time to display the web page.
  • Make the use of Keep-Alive
By making use of Keep-alive, it can avoid the need for repeated opening and closing of a new connection. It also fetches and serves all the requested files from the server in a single communication itself.
So, enabling Keep-alive, the load time of the site gets quicker and that results in better performance.

5. How to enable Keep-Alive?

Keep-alive is enabled using the “Connection: Keep-Alive” HTTP header. If keep-alive is not enabled it is likely your HTTP headers are stating “connection: close”
Change”connection: close” to “connection: keep-alive” to enable Keep-alive. Enabling Keep-alive depends on what server you are using.
Keep-alive is the task of the server-side. In Shopify, Enable Keep-alive is already set to default.

6. Benefits of Keep-Alive

  • Creating new TCP connections can use many resources such as CPU and memory usage. Keeping connections alive longer can reduce this usage and the generated HTTP requests that are very small.
  • The ability to serve multiple files using the same connection to reduce latency and allow web pages to load faster. So, it also gets better ranking due to excellent performance.
  • HTTPS connections (content over Secure Socket Layer) are very resource-intensive. Hence, it is highly recommended to enable Keep-Alive for HTTPS connections.

Leave A Comment