Learn About The Web

WordPress Performance Tips – Enable Keep Alive

Wordpress Performance Tips - Enable Keep Alive

Keep-Alive allows a Transmission Control Protocol (TCP) connection to gain access to several files from the server to the browser, rather than having to create a connection for each new request or file.

It is often termed as a persistent HTTP connection but how does it work?

Anyone who has a website knows how a web browser and server works, how they connect and coordinate every request. When you go to any webpage, the browser will create a new connection with the server and then send requests for specific files; the server gives the thumbs-up and the browser gets the go-ahead.

The browser will download that file and then another connection is made for another file, and so on.

Now, let’s suppose that your browser is requesting 10 files so that a webpage can be displayed.

That means your browser needs to create a connection for each one, that’s 10 connections and each one must be requested individually – that can really slow down the speed the webpage loads at.

Enable Keep-Alive

Enabling Keep-Alive is one way to ensure a browser creates just one connection to access every file it needs in one hit. This results in fewer requests being sent to the server, fewer server resources being used, and much faster page load speeds.

It doesn’t matter whether your website is a simple blog, or a full-on powerhouse e-commerce site loading speed is important so enabling Keep-Alive is also important.

You may find that your web host already has it enabled by default so do check with them first before you do any of the following methods.

Enabling Keep-Alive Using .htaccess

Find your .htaccess file and open it. Add the following code to it:

# TN START ENABLE KEEP ALIVE

Header set Connection keep-alive

# TN END ENABLE KEEP ALIVE

This should be added right at the end of the .htaccess fie, after the very last line and it will add a Keep-Alive HTTP header enabling the feature.

Enabling Keep-Alive in Apache

Many of the new Apache servers already have Keep-Alive enabled by default, However, if it isn’t, you need to access the HTTP Server Configuration file for your Apache server. Look for the file in

– /etc/httpd/conf/httpd.conf

And then add the following code to the 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

Enabling Keep-Alive in Nginx

If you use an Nginx server, you will probably find that Keep-Alive has already been enabled.

If, on the slim chance, that it hasn’t, you will need to go into the core module of the server, which is called ngx_http_core_module and look for where it says ‘keepalive_disable’. Change this to read enable and you should be good to go.

Have you done this? Is Keep-Alive enabled on your website? Make sure it is and enjoy much faster loading times.