What is Keep Alive?

Keep alive is a method that allows an HTTP client-server conversation over the same TCP connection, rather than opening one for each new request. In other words, it is a communication between the web server and the browser that declares “you can download more than one file at a time”. Keep Alive is also called “Persistent connection / persistant connection” and allows you to reduce the download times of the resources needed to compose a web page.How keep-alive works

How to enable keep-alive

The Keep-alive message is enabled using the “Connection: Keep-Alive” HTTP header . If keep-alive is not enabled, your website’s HTTP headers are likely to declare connection: close . Change the header to connection: keep-alive to enable keep-alive.

Enabling keep-alive depends on which server you are using and what you can access. Let’s see the most common methods below.

Enable keep-alive with the .htaccess file

If you do not have access to the web server configuration file, you can enable the use of keep-alive through the .htaccess file.

By inserting this directive to your .htaccess file, the web server will add keep-alive headers, which overrides most of the server’s or hosting provider’s rules.

Enable keep-alive on Apache

If you can access the Apache configuration file, you can enable keep-alive permanently.

Enable keep-alive on Nginx

Keep-alive is managed by the HttpCoreModule module . There is a specific directive you need to check: keepalive_disable . If you see this directive, make sure you know why it’s disabling keep-alive before removing it.

How to verify keep-alive?

The tools for checking page load times always show if keep-alive is active or not:

  • PageSpeed ​​Insights
  • GTmetrix ( my guide )
  • WebPage Test

Why is keep-alive used?

To view web pages, a browser must request files from a web server. There is a brief communication in which the browser requests a file and the web server responds in the affirmative or negative. The browser obtains the HTML file and reads it and then requests other files with references in the HTML: such as CSS, Javascript or images.

Web pages are often made up of a collection of many files, and if a new connection needs to be opened for each file, it could take much longer to load the page. When keep-alive is not enabled, this process can increase the time it takes to download server resources.

Why isn’t keep-alive already activated?

Some webmasters mistakenly believe they don’t have to worry about keep-alive because HTTP connections nowadays are persistent by default (keep-alive enabled). This is partly true, but many people use shared hosting environments or web servers which could close connections without the user’s knowledge. This is mainly due to performance reasons and, since millions of pages are hosted in shared environments, it is important to check the behavior of your web server with the tools mentioned above.

LEAVE A REPLY

Please enter your comment!
Please enter your name here