Where can I find a list of textual MIME types?

2019-05-10 15:54发布

问题:

I want to make a list of MIME Types which can be compressed by gzip. The first obvious ones to includes are those which begin with "text/". Beyond that I can only add the ones off the top of my head which I know are textual, like "application/json".

Is there a list, canonical or otherwise, that I can refer to?

回答1:

IANA manages the official list of Media Types

But to know which ones are textual, you'd need to consult RFCs in which they were proposed.



回答2:

Here is Perl's list. Seems too small...

https://github.com/mikegrb/File-Compressible/blob/master/lib/File/Compressible.pm#L12-L27



回答3:

Maybe better is to make a list of types to not try to compress with gzip. Those would be the types that you know are already compressed. In particular, image, video, and audio types.

It is better to be inclusive than exclusive, since compressing something already compressed only impacts CPU time on the server, and has a vanishingly small effect on bandwidth. On the other hand not compressing something that can be compressed could have a big effect on bandwidth and therefore user experience. Many types could be added that aren't on your list. You'll totally miss the benefit of compressing those with a whitelist. Better to compress what you don't know about, and only not compress what you know for sure is already compressed.



回答4:

If you're here looking for a list to put in your gzip_types for Nginx, this is a good starting point (taken from a quick scan of obviously compressable types from /etc/nginx/mime.types):

gzip_types text/css text/xml application/javascript application/atom+xml application/rss+xml text/mathml text/plain text/x-component image/svg+xml application/json application/vnd.google-earth.kml+xml application/x-perl application/xhtml+xml application/xspf+xml;

(text/html is always included, and should not be duplicated in gzip_types)