formats

Speed Up Website in Apache by Enabling Compression and Leveraging Browser Caching



Google has a cool website to inspect your website for speed improvements. Two of the main areas are leveraging browser caching as well as enabling compression for your website. I’ll show you how to set this up in Apache!



Firstly, here is that website. Put in your site for a quick review:

https://developers.google.com/speed/pagespeed/insights




If you receive results stating a need to Leverage browser caching, try the following.

First, enable the mod_expires module in Apache.

Debian / Ubuntu:

$ sudo nano a2enmod expires



CentOS / Red Hat with Apache 2.2.x, make sure mod_expires is uncommented:

$ sudo nano /etc/httpd/conf/httpd.conf



Here is a suggested configuration for mod_expires that can be placed either in a VirtualHost config or just in .htaccess:

<IfModule mod_expires.c>

    ExpiresActive On
    ExpiresDefault "access plus 1 month"

</IfModule>



If you receive results stating a need to Enable compression, try the following.

First, enable the mod_deflate module in Apache.

Debian / Ubuntu

$ sudo nano a2enmod deflate




CentOS / Red Hat with Apache 2.2.x, make sure mod_deflate is uncommented:

$ sudo nano /etc/httpd/conf/httpd.conf




And below is a suggested configuration for mod_deflate that can be placed either in a VirtualHost config or just in .htaccess:

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
	
    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

</IfModule>




After putting in changes, re-test your page at
https://developers.google.com/speed/pagespeed/insights



2 Responses

  1. Jaime

    Cool and interesting link! There’s tons of developer tools I never use, but probably should. Thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Home linux Speed Up Website in Apache by Enabling Compression and Leveraging Browser Caching