Using keep-alive connections to improve performance
Keep-Alive connections can improve the performance of your website. Follow our step-by-step instructions to enable it for your site.
This article describes how to use keep-alive connections in Apache to help improve performance.
How to enable keep-alive connections
Keep-alive connections use a single TCP connection to handle multiple HTTP requests and responses. Instead of opening a new TCP connection every time a browser sends a request, keep-alive connections enable clients and servers to communicate more efficiently and use fewer resources.
Many performance testing sites, such as GTMetrix, check if keep-alive connections are enabled for a site. If they are disabled, you receive a lower site performance score.
If keep-alive connections are disabled for your site, you can easily enable them. To do this, follow these steps:
-
Edit or create an .htaccess file in your site's document root directory.
-
Copy the following lines and paste them into the .htaccess file:
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
- Save your changes to the .htaccess file. Keep-alive connections are now enabled.
Tip
To verify that keep-alive connections are enabled, you can examine the raw HTTP headers sent between the browser and web server. To do this, use a browser plugin that displays the raw headers such as Live HTTP headers for Mozilla Firefox, or the Developer Tools feature in Google Chrome. When keep-alive connections are enabled, Apache adds the following line to the HTTP response header:
Connection: Keep-Alive
More Information
For more information about keep-alive connections, please visit https://en.wikipedia.org/wiki/HTTP_persistent_connection.
Updated 1 day ago