1

I am not able to get compressed html pages in my browser even though I am 100% sure mod_deflate is activated on my server.

My htaccess file has this code snippet :

<IfModule mod_deflate.c>
   <Files *.html>
   SetOutputFilter DEFLATE
   </Files>
</IfModule>

A non compressed excerpt of my content is:

<div>
   <div>
   Content
   </div>
</div>

With the htaccess code I am using, I would expect to get the output below in my browser (no space and no tabs at the beginning of each line):

<div>
<div>
Content
</div>
</div>

Is there something wrong with the code I am using in the htaccess file?

Is keeping all tabs in front of each html line after compression the normal behavior of mod_deflate? If so, would you recommend that I switch tabs with spaces in my html code to get the desired effect?

Thanks for your insights on this

Vincent
  • 1,651
  • 9
  • 28
  • 54

1 Answers1

3

For the Deflate output filter to compress the content

  1. Your content should be at least 120 bytes; compressing lesser bytes increases the output size.

  2. The http client making the request should support gzip/deflate encoding.

Most modern Web browsers support gzip encoding and automatically decompress the gziped content for you. So what you are seeing using a Web browser's View Page Source option is not the compressed content. To verify if your browser received a compressed content, hit the F12 Key, select the Network tab and your requested page. If the response header has Content-Encoding: gzip, you can be sure the compression worked.

In Firefox, you can remove support for gzip,deflate by going to about:config and emptying the value for network.http.accept-encoding. Now with no support for gzip, Firefox will receive uncompressed content from your Apache server.

Alternatively, if you want to see the compressed content, you can use a client that does not automatically decompress the contents for you (unless you use --compressed option).

You can use curl for this:

curl -H "Accept-Encoding: gzip,deflate" http://example.com/page.html > page.gz
kums
  • 2,661
  • 2
  • 13
  • 16
  • Gzip is in the response header. That would mean the compression works. However, when I submit the page on Google PageSpeed Insights, it keeps telling me I should minify html resources. I don't understand how the html page could not already be minified if the compression does work in Apache. That does not make sense to me. Thank you. – Vincent Oct 13 '14 at 22:59
  • It means you can simplify your html; remove unnecessary tags etc. – kums Oct 13 '14 at 23:01
  • The reco is really about minifying the page and removing spaces, tabs etc. https://developers.google.com/speed/docs/insights/MinifyResources – Vincent Oct 13 '14 at 23:03
  • Totally makes sense now after reading the gzip-versus minify link. Many thanks. – Vincent Oct 13 '14 at 23:08