This quick guide will show you how to quickly and easily make your WordPress site faster with gzip and caching.

Let’s take a demo site demo.rocketwp.co.uk, testing via GTMetrix shows pretty poor results.

Fist things first, we install WP-Rocket, our preferred caching solution, Imagify  to optimise our images.

Back to GTMetrix, things have improved but still getting a terrible score due to gzip and caching.

Let’s tackle gzip first, follow the steps below to enable gzip on your server for both Apache and Nginx

Connect to your server via ssh

To enable gzip on Apache execute the following:

sudo a2enmod deflate

Don’t forget to restart Apache:

sudo service apache2 restart

To enable gzip for Nginx we are going to create a new config file:

sudo nano /etc/nginx/conf.d/rkt.conf

Enter the following text:

gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

Save and exit

Don’t forget to restart nginx:

sudo service nginx restart

If we check back with GTMetrix the issues regarding gzip should now be gone, if not check that you have restarted both Apache and Nginx.

Now lets deal with caching.  Apache first, execute the following command:

sudo a2enmod expires

Then restart Apache

sudo service apache2 restart

Caching on Nginx involves adding more to the configuration file we created earlier:

sudo nanao /etc/nginx/conf.d/rkt.conf

Add the following lines:

location ~* \.(css|js|ico|gif|jpe?g|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
expires max;
}

Now restart nginx:

sudo service nginx restart

If we now retest the site with GTMetrix we should see that most of the issues with gzip and caching are gone. Why most? Only the data served from your website will be covered by these configuration changes, if you check through the links provided in the GTMetrix report none of them should be URL’s on your server.

All our servers have gzip and caching implemented as standard, we also support HTTP/2 and the latest versions of PHP and MySQL.  Our servers are updated according to the releases from Plesk – we aim to upgrade within 24 hours of being notified of an update.

Leave a Reply

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.

Pin It on Pinterest

Share This