Reputation: 9476
In several nginx tutorial sites explaining "how to set up gzip compression," I've seen this list of MIME types repeated:
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
However, I immediately found that this list did not result in compression being enabled for JavaScript in Chromium. I had to add application/javascript
to the list. Which leads me to believe this list is outdated.
Is there a definitive list of all the content types I would want to gzip?
Upvotes: 4
Views: 1585
Reputation: 4361
There is no definitive list of the file types you would want to gzip. Any file type readable as plain text (i.e. non-binary files) are able to be gzipped, and so a "definitive" list would be massive. Therefore, it ultimately depends on which file types you are actually serving, which you can check for any given file via the HTTP Content-Type
header.
If you want to be doubly sure you are covering all possible MIME types for a particular extension (which I think is reasonable), Looking at this SO post, this text file contains a pretty darn exhaustive list.
It's important to note that some binary file types like .png
and .pdf
(even .woff
) incorporate compression into the format itself and as such should not be gzipped (because doing so could produce a compressed file larger than the original). My rule of thumb is: if my code editor can't read the file as UTF-8 text, gzipping the file would not be wise (or at least it wouldn't be very efficient).
FWIW, I typically gzip the following formats (in my Apache .htaccess
) on my site:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml image/svg+xml
</IfModule>
Upvotes: 5