Easy way to speed up your website

Nginx config file for this site didn't have gzip compression enabled. I copied the default file from here Recipes Drupal updated server_name and site path, and never bothered to check if compression is enabled or not.

As soon as I was aware of this, I decided to do a little test. I checked the page speed of my site by using the Google PageSpeed Insights tool. These are the results without gzip compression enabled.

Image
Image

After doing this initial speed test I update the nginx config file. I added the following lines:

gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;

These are the speed results with compression enabled.

Image
Image

Nice! Adding just 5 lines of code to my nginx config file increased the page load time by 48% on mobile, and 10% on desktop.

Btw, this is where I added those lines. Just beneath the path reference.

server {
  server_name gorannikolovski.com;
  root /var/www/gorannikolovski.com/web; ## <-- Your only path reference.

  gzip on;
  gzip_vary on;
  gzip_min_length 1000;
  gzip_proxied expired no-cache no-store private auth;
  gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
  gzip_disable "MSIE [1-6]\.";

  access_log /var/log/web/gorannikolovski.com_access_log;
  error_log /var/log/web/gorannikolovski.com_error_log;

  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }

  ...
  ...

}

Don't forget to restart the Nginx with this command after you update the file:

service nginx restart

It's not always necessary to get a better server if you are not happy with the site speed. Sometimes you just have to tweak the existing one to get better results.

About the Author

Goran Nikolovski is a creator, speaker, open-source contributor, web developer specialized in Drupal and DevOps enthusiast. He is the founder of this website and he enjoys sharing his knowledge and experiences.