How to Enable Keep-Alive in WordPress to Speed up Your Site

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 it works and how to enable Keep-Alive in WordPress using .htaccess or on Apache/NGINX servers.

Updated on

Learn How to Enable Keep-Alive in WordPress. You need to add ‘Connection: Keep-Alive’ HTTP header in your server in order to enable Keep-Alive. You can also Enable Keep-Alive using .htaccess in WordPress. Or you can choose to edit config file of your Apache/NGINX servers if you do not have access to .htaccess file. The easiest way to Enable Keep-Alive using .htaccess is to add a piece of code (given below).

How to Enable Keep-Alive in WordPress to Speed Up your site
How to Enable Keep-Alive in WordPress to Speed Up your site

Before we start about the best practices to Enable Keep-Alive in WordPress and the dos and don’ts. First of all, we need to understand What Keep-Alive is? and How actually Keep-Alive works?

Fastest WordPress Hosting Anywhere!

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 instead of creating new connection for every new request (file). Keep-Alive also known as persistent HTTP connection.

Furthermore, Lets’ discuss about 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 web-server and sent a request to access a particular file, and server gives OK (go ahead) to the browser.

As a result, Browser started downloading the file, than create another connection for second file and the process goes on.

Suppose, if your web browser requires 10 (TEN) 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.

Keep-Alive-Disabled (How to Enable Keep-Alive using .htaccess in WordPress)
Keep-Alive Disabled

Therefore, Enabling Keep-Alive help browsers to create only SINGLE connection to access all the files from web server in one go (or in single OK). It significantly reduces number of requests to the web-server, and as a result that reduces Server CPU Uses (Server Load) as well. In addition to that, you will get considerable improvement in page loading speed.

Keep-Alive-Enabled (How to Enable Keep-Alive using .htaccess in WordPress)
Keep-Alive Enabled

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. Because, most of the modern hosting services had already activated Keep-Alive by default. However, you should 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.

Finally, let’s discuss, how to Enable Keep-Alive using .htaccess in WordPress or on Apache/NGINX servers.

How to Enable Keep-Alive using .htaccess file in WordPress

You need to add 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. Either, 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 enabled, 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

In almost all the NGINX servers, Keep-Alive comes enabled by default. However, if it is not enabled you can check the same by finding ‘keepalive_disable’ in NGINX core module (ngx_http_core_module).

Have you Enabled Keep-Alive on your website. YES, NO, Not Sure. Do check it again and Enable Keep-Alive using .htaccess in WordPress now.

Hope you find this guide useful. Which method you use to Enable Keep-Alive? Did you find any improvement in page loading speed? Do let us know in the comment section below.

Cheers!

In addition to that you may be interested to learn about WordPress PageSpeed Optimization:
Leverage Browser Caching in WordPress without Plugin
Is your blog optimized for SEO – Best settings for Yoast Plugin
Increase WP Speed – Enable Gzip Compression in WordPress via .htaccess file
Optimize Images in WordPress for PageSpeed
Optimize WordPress Robots.txt file for SEO and PageSpeed

Photo of author
Saurabh K
Saurabh K is a technology enthusiast and part-time blogger. He loves to explore the efficient use of technology and gadgets. He is an outlier and lensman. Add him in your social circle to know more.
Disclaimer: Affiliate links of some product(s) are being used on this page, if you follow the link and make a purchase, we may receive compensation from respective companies. This compensation comes at no additional cost to you.

6 thoughts on “How to Enable Keep-Alive in WordPress to Speed up Your Site”

  1. Avatar of Shatyajit

    Can I use this method for shared hosting?

    Reply
  2. Avatar of Shahid

    Hi,

    As I add the code in .htaccess file it shows the “500 Internal Server Error” can you please guide? why this is happening.

    Reply
  3. Avatar of JAHMK

    Really helpful, for me, it was increased the performance grade from F to B

    Thank you.

    Reply
  4. Avatar of Harshita Jain

    Hi,

    I have added the same code in .htaccess file. But, there is no change in it. The keep alive is still not enabled at my end.

    # TN START ENABLE KEEP ALIVE

    Header set Connection keep-alive

    # TN END ENABLE KEEP ALIVE

    Reply
    • In that case, you should contact your hosting provider. In most of the case KEEP ALIVE is enabled by default.

      Reply

Leave a Comment

Your email address and website details will not be published. Required fields are marked with *.