32

I ran a Google Page Speed and it says I scored 57/100 because I need to "Enable Keep-Alive" and "Enable Compression". I did some Google searches but I can't find anything. I even contacted my domain provider and asked them to turn it on, but they said it was already on.

Long story short:

1.) What is Keep-Alive?

2.) How do I enable it?

Ross
  • 1,963
  • 2
  • 21
  • 25
John Doe
  • 3,239
  • 13
  • 57
  • 107

6 Answers6

24

Configure Apache KeepAlive settings

Open up apache’s configuration file and look for the following settings. On Centos this file is called httpd.conf and is located in /etc/httpd/conf. The following settings are noteworthy:

  • KeepAlive: Switches KeepAlive on or off. Put in “KeepAlive on” to turn it on and “KeepAlive off” to turn it off.

  • MaxKeepAliveRequests: The maximum number of requests a single persistent connection will service. A number between 50 and 75 would be plenty.

  • KeepAliveTimeout: How long should the server wait for new requests from connected clients. The default is 15 seconds which is way too high. Set it to between 1 and 5 seconds to avoid having processes wasting RAM while waiting for requests.

Read more about benefits of keep alive connection here: http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

Tamik Soziev
  • 12,908
  • 5
  • 39
  • 53
18

Keep-alive is using the same tcp connection for HTTP conversation instead of opening new one with each new request. You basically need to set HTTP header in your HTTP response

Connection: Keep-Alive

Read more here

pavel_kazlou
  • 1,839
  • 3
  • 23
  • 34
6

I had the same problem and after a bit of research I found that the two most popular ways to do it are:

  1. If you do not have access to your webserver config file you can add HTTP headers yourself using a .htaccess file by adding this line of code:

    <ifModule mod_headers.c> Header set Connection keep-alive </ifModule>

  2. If you are able to access your Apache config file, you can turn on keep-alive there by changing these 3 lines in httpd.conf file found here /etc/httpd/conf/

    KeepAlive On

    MaxKeepAliveRequests 0

    KeepAliveTimeout 100

You can read more from this source which explains it better than me https://varvy.com/pagespeed/keep-alive.html

AndreiO
  • 436
  • 5
  • 7
4

To enable keep-alive through .htaccess you need to add the following code to your .htaccess file:

<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>
0

When you have "keep-alive" enabled you tell the browser of your user to use one TCP/IP connection for all the files(images, scripts,etc.) your website loads instead of using a TCP/IP connection for every single file. So it keeps a single connection "alive" to retrieve all the website files at once. This is much faster as using a multitude of connections. There are various ways to enable keep-alive. You can enable it by

  • Using/Editing the .htaccess file
  • Enabling it through access to your web server(Apache, Windows server, etc.)

Go here for more detailed information about this.

With the "Enable Compression" part they mean you should enable GZIP compression (if your web host hasn't already enabled it, as it's pretty much the default nowadays). The GZIP compression technique makes it possible for your web files to be compressed before they're being sent to your users browser. This means your user has to download much smaller files to fully load your web pages.

0

To enable KeepAlive configuration, Go to conf/httpd.conf in Apache configuration and set the below property : KeepAlive On