Rule from network under performance category
Passmarked is made out of users just like you who helped supply some content. Click below to contribute to this rule. We need you.Add content to this rule
GZIP is used to compress text based responses before sending them to the client who will uncompress them.
This allows clients to download a considerably smaller file by taking a small expense of compressing on the server when sending the response.
In general GZIP can save your users 80%+ on file sizes to download.
Certain file types would not gain any advantage when enabling GZIP and in fact might cause wasted resources.
These file types include:
As these files are already compressed your users will only be downloading a file that is almost the same size at the expense of your server having to compress it as well.
Solutions to enable GZIP depends on how your website might be hosted, as this dictates what can be changed. For various types of situations we have listed a few examples to enable the setting and/or services that could be used.
It's worth noting that external services like Cloudflare that do various things to speed up your website can be used in place of any of these provided solutions.
If your paying a small amount and gaining access to your website through CPanel and uploading changes via FTP you're probably on a shared host.
What this is, is that the provider gives you limited access to certain folders where your website files will be located and then hides all of the server configuration to allow quick and simple website development.
The downside is that various clients may be using the same server your website is currently running on and could slow down your website if they start receiving attention.
In this example you will not be able to edit configuration on the server to enable GZIP. To enable GZIP and speed up your website you'll need to either:
If you are indeed able to configure your web server, that server happens to be NGINX. Enabling GZIP is a simple case of adding the directives shown below.
These can either be added to the global nginx.conf file to enable for all websites or per server as you see fit.
With each of these parameters allowing you to configure:
Accepts either "on" or "off" and tells NGINX to enable GZIP compression.
When a file is smaller or equal to the amount of bytes configured on this property the file will skip compression.
Reason for this is that as the file size decreases to small sizes <1kb GZIP becomes less and less useful. To save server resources these files are normally served as is, or even better embedded in the page itself as a data image.
Specifies the "compression level" that signifies how much NGINX will try. This level has a direct correlation with how much processing power will be required to serve and compress these files. On high-volume sites higher numbers here will certainly be felt on system load and capacity.
A test ran by a user from ServerFault shows the following compression rates:
text/html: 0 55.38 KiB (100.00% of original size) 1 11.22 KiB ( 20.26% of original size) 2 10.89 KiB ( 19.66% of original size) 3 10.60 KiB ( 19.14% of original size) 4 10.17 KiB ( 18.36% of original size) 5 9.79 KiB ( 17.68% of original size) 6 9.62 KiB ( 17.37% of original size) 7 9.50 KiB ( 17.15% of original size) 8 9.45 KiB ( 17.06% of original size) 9 9.44 KiB ( 17.05% of original size)
gzip_disable "<regex here>";:
Tells NGINX to disable GZIP on user agents that match the given regex. A good starting point would be to add <= IE6 browsers to this property as GZIP is not supported:
gzip_disable "MSIE [1-6].(?!.*SV1)";
Allows control of when NGINX will enable GZIP for proxy requests based on the request and response. Various options include:
A safe default is
any that will simple enable GZIP for all proxied requests but these options allow environment specific settings.
`gzip_types: <content-type> <content-type>;:
Configures which Content-Type's should be compressed. This allows fine control over which type of files should be compressed to save server processing power if it's not needed.
For a start it's a suggested to enable at least:
After enabling and configuring these properties NGINX can be restarted and you should not see an immediate decrease in file sizes that the client has to download.
If on Ubuntu run the following:
and be sure to restart Apache using:
service apache2 restart
To enable GZIP add the following to your .htaccess in the root of your website.
With each of these properties allowing you do the following:
Just enables the DEFLATE module which will handle compressing the response.
AddOutputFilterByType DEFLATE <type> <type>:
Specifies which Content-Type's should have GZIP enabled to save on server performance with already compressed files as noted above.
A good default to list here would include:
BrowserMatch <regex> [<options>]:
Allows setting up compression and options on a per browser action. The regex passed will be matched to the user agent given in the request.
For example to disable GZIP on IE6 and older add the following:
BrowserMatch \bMSI[E] !no-gzip
After enabling and configuring these properties Apache can be restarted and you should not see an immediate decrease in file sizes that the client has to download.
To read more about GZIP and optimising performance with this technology see:
Passmarked works best when you have an account. It allows you to keep a dashboard with saved data of the sites you have run through the system, we’ll alert you about important updates and you get access to the Passmarked Slack forum.Sign up to get started