2

I am using Firefox and when I set the Accept-Encoding to deflate,gzip I get Content-Encoding: gzip in the response header. When I use Accept-Encoding as either deflate or gzip the Content-Encoding is removed from the header.

Can anyone please explain me why ? Is there any apache configuration I need to consider ?

2 Answers 2

1

If you are serving a .gz file, perhaps you are looking to add an association between the file extension and the desired mime-type with mod_mime. The following can be added to the VirtualHost configuration.

AddEncoding x-gzip .gz

Alternatively, a more complete example for serving pre-compressed content involves not just adding the encoding-type but also disabling mod_deflate and resetting the content-type. This example uses mod_header to add the encoding-type.

<IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist 
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]

    # Serve gzip compressed JS files if they exist 
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]


    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
    RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]


    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header append Content-Encoding gzip

      # Force proxies to cache gzipped & 
      # non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
</IfModule>

(Note the above adds DOCUMENT_ROOT to the RewriteCond file path from the referenced sample since I believe it is needed when used in the VirtualHost context from 2.2+.)

1
  • I notice that I linked to documentation for Apache 2.4 while the original question referenced 2.2. While I haven't tested against 2.2, a cursory review makes me think it should work with 2.2 as well.
    – user650881
    Jul 17, 2017 at 21:15
1

Refer to the RFC it offers details about which values can be used in Accept-Encoding and how a server tests whether a content-coding is acceptable, according to an Accept-Encoding field, using these rules,

https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .