gzip and cache all the things
Problem
Nowadays I host this blog and some other stuff on a small vps on digitalocean. Not really because it is the best idea (neither speedy not super cheap), but mostly because I wanted to do it that way and keep my administration skills fresh.
Anyway: today while looking at Google page speed as part of the ‘refresh’ I talked about in I noticed some terrible scores:
Scrolling over the stuff I was expecting (outdated libs, unoptimized css, …) I found some glaring problem in that the gzip compression was not enabled.
Settings
After setting the following lines in my nginx.conf http block
gzip on;
gzip_proxied any;
gzip_types text/plain text/html application/xml text/css text/js text/xml application/javascript application/x-javascript text/javascript application/json application/xml+rss;
gzip_vary on;
gzip_disable "msie6";
as well as enabling caching for static files in my server block
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 5d;
add_header Pragma public;
add_header Cache-Control "public";
}
pagespeed reports:
Not bad for a few lines.
Considerations
The page speed readings were taken from the mobile testing configuration. Compared to the Desktop setting file size is weighted more heavily hence the big bump from enabling compression.
Compression increases server load a bit (as resources need to be compressed) and caching can have some issues with delivering updated files to clients so it’s not completely free and should be kept in mind.