user1576748
user1576748

Reputation: 683

Content-Encoding: gzip doesn't work for text/html Content-Type

I use the config below in my .htaccess. However, whilst other Content-Type get gzipped, the text/html Content-Type doesn't. Anyone knows why?

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary
</IfModule>

enter image description here

enter image description here

Upvotes: 2

Views: 3338

Answers (3)

paulito415
paulito415

Reputation: 236

For me it was because of the charset. Whereas:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json text/json

did not work,

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json text/json application/javascript;charset=utf-8 text/css;charset=utf-8

worked. I didn't feel like looking for better answers like how I can instruct Apache to parse out the charset from the content type and I figured that just giving the whole String as is should work. Fortunately it did for me.

Upvotes: 0

jnwcki
jnwcki

Reputation: 1

I ran across this while having the same issue on a Magento site. In my case the answer was to enable zlib output compression in php.ini because the html was being dynamically generated.

Upvotes: 0

Dimas Pante
Dimas Pante

Reputation: 2521

Try to insert the AddType for html before it, like:

AddType text/html .html .htm
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary

Here you have a complete list of MIME types: http://www.htaccess-guide.com/adding-mime-types/

*Edit: Try to change the rule then:

<ifModule mod_deflate.c>
    <filesMatch "\.(js|css|html|php)$">
        SetOutputFilter DEFLATE
    </filesMatch>
</ifModule>

Upvotes: 1

Related Questions