Search code examples
regexgzipmime-typeshttp-compression

How to configure mod_gzip to exclude all but a few mime types?


I need to configure a .htaccess file to enable compression of HTTP responses using mod_gzip. I can get the basic compression working.

However, I want to disable compression for all MIME types, except for the following:

  • text/*
  • message/*
  • application/x-javascript
  • application/json
  • application/atom+xml
  • application/xaml+xml

I know I can use statements such as mod_gzip_item_exclude mime ^regex$ to include or exclude or exclude certain mime types, but I can't seem to get it quite right. How should I configure my .htaccess file?


Solution

  • See if this works:

    ^(?:(?:(?:text|message)\/\*)|(?:application\/(?:x-javascript|json|(?:atom|xaml)\+xml)))$