In this tutorial you‘ll learn how you can use eSATA/USB port available on your laptop to charge smartphone using USB data cable even when laptop is power off. Sometimes your smartphone battery drained out or your iPod…
To enable Keep-Alive you need to add ‘Connection: Keep-Alive’ HTTP header in your server. In WordPress, you can enable Keep-Alive by editing your .htaccess file, or you can edit config file of your Apache/NGINX servers if you do not have access to .htaccess file. The easiest way to enable Keep-Alive is to put a piece of code (given below) in your .htaccess file.
Before we start about the best practices to enable Keep-Alive in WordPress and the dos and don’ts. We need to understand what Keep-Alive is and how actually it works.
What is Keep-Alive and how it works
Keep-Alive is a technique to let one TCP (Transmission Control Protocol) connection to access multiple files from server to web browser in place of creating new connection for every new request (file). Keep-Alive also known as persistent HTTP connection.
Lets’ discuss how it works, you might know about the connection and coordination process of a web browser and server. When you visit a webpage, your web browser create a connection with webserver and sent a request to access a particular file, and server gives OK (go ahead) to the browser.
Browser download the file, than create another connection for second file and the process goes on. Suppose if your web browser requires 10 files to display a webpage, browser has to create 10 separate connections after each file download and request one by one to web server for OK to access files.
Enabling Keep-Alive help browser to create only SINGLE connection to access all the files from web server in one go. It significantly reduces number of requests to the webserver that reduces server CPU uses as well. In addition, you get considerable improvement in page loading speed.
How to enable Keep-Alive in WordPress
Whether you own a blog or a website, page-loading speed always matters and these simple techniques will boost your webpage loading speed by enabling Keep-Alive in WordPress.
Before applying any method, I would suggest you to check whether, is it already enabled on your website or disabled. You can check it by using this link.
Enable Keep-Alive plays an important role in order to increase your website loading speed. This is one of the most commonly adaptive method by pro-bloggers to reduce website loading time. Let us discuss, how to enable Keep-Alive in WordPress using .htaccess or on Apache/NGINX servers.
How to enable Keep-Alive using .htaccess file in WordPress
You need to put the given below piece of code into your .htaccess file.
# TN START ENABLE KEEP ALIVE <ifModule mod_headers.c> Header set Connection keep-alive </ifModule> # TN END ENABLE KEEP ALIVE
Add this code after the last line in your .htaccess file; it will add Keep-Alive HTTP headers that enables Keep-Alive.
If you do not know how to edit .htaccess file or where to find it. Here is a complete guide about how to edit .htaccess file in WordPress.
In very few cases .htaccess did not created automatically with WordPress installation, you can create one by yourself, more details are here how to create .htaccess file.
Enable Keep-Alive in Apache
In most of the new Apache servers, Keep-Alive should be auto enabled, if it is not. Find Apache HTTP Server configuration file (httpd.conf) of your server, you can find it here (/etc/httpd/conf/httpd.conf) and add the below written code in that file
# Set it On to enable Keep-Alive, Off to disable Keep-Alive KeepAlive On # Set maximum requests per connection, set 0 for unlimited request, 100 request per connection is ideal MaxKeepAliveRequests 100 # Set per connection timeout for next request KeepAliveTimeout 15
Enable Keep-Alive in NGINX
Keep-Alive in NGINX servers comes enabled by default if it is not enabled you can check the same by finding ‘keepalive_disable’ in NGINX core module (ngx_http_core_module).
Is keep-alive enabled on your website, do check it again.
Hope you find this guide useful, which method you use to enable keep-alive? Did you find any improvement in page loading speed? Do share in the comment section below.
More to read: