In short, Keep-Alive is a great way to reduce the use of resources and increase the speed of your site at the same time.
Before beginning this guide, you need the following:
First, you must analyze a website with a tool like GTmetrix to determine if the keep-alive is enabled or disabled on the server. Here are the results after the analysis of a test page:
On some servers or hosting providers, the keep-alive is enabled by default. If your analysis gives a score of 100%, there is nothing more that needs to be done.
There are several ways to activate the Keep-Alive and everything depends on your server or hosting provider.
Here are some options:
To enable Keep-Alive, add the following code to your .htaccess file. Enable the Keep-Alive using. .htaccess override any server settings and activate the connection.
<IfModule mod_headers.c> Header SET CONNECTION keep-alive </ IfModule>
This method should work on most shared hosting providers Linux. If you do not know where to find the .htaccess , take a look at this tutorial .
If you have access to the Apache configuration file, you can enable the extension there. Here is the appearance of the configuration:
# # KeepAlive: Whether or not to allow persistent connections (more than # One request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # During a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 50 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # Same client on the same connection. # KeepAliveTimeout 10
If you can not locate the file httpd.conf , run the following command on the command line:
find / -name Httpd.conf
The Keep-Alive is enabled by default on NGINX, however, in some cases, it can be disabled. You can activate it using HttpCoreModule . Look for the keepalive_disable value, which is in many cases the reason keep-alive is not working. Before you activate it, make sure you know why he went off first before attempting any changes.
If you are using a Windows-based server, you can easily activate the Keep-Alive extension using the command line.
The following command will enable:
appcmd set config / section: httpProtocol / allowKeepAlive: true
And if you want to disable it, use:
appcmd set config / section: httpProtocol / allowKeepAlive: false
You can also consult the official tutorial Microsoft for some extra options.
After the Keep-Alive is fully enabled, run another check with GTmetrix or any other site performance analysis tool to see if everything is working. Here are the results after the Keep-Alive was enabled:
You can also check the Keep-Alive is working checking your HTTP header. This can be done via terminal using the following command:
curl -I http://example.com/example.php
Here’s an example:
-i curl http://hostinger.com/index.php
The results are:
HTTP / 1.1 301 Moved Permanently Connection: keep-alive Server: nginx Date: Fri, 23 Dec 2016 18:58:14 GMT Content-Type: text / html Content-Length: 178 Location: https://www.hostinger.com/index.php Connection: Keep-Alive The part means that Keep-Alive is working.
In short, activate the Keep-Alive is a great way to improve the speed and performance of your website. The persistent TCP connection will ensure faster load times and more efficiently, keeping your visitors satisfied.
If you want to further improve your site, these articles will also help:
Improving Website Performance: Taking advantage of the browser’s cache
Improving site performance: Compression Gzip
Improving site performance: scale images Server
Improving Website Performance: Using Progressive JPEG images