views:

370

answers:

1

Google PageSpeed says I should "Specify a Vary: Accept-Encoding header" for JS and CSS. How do I do this in .htaccess?

+1  A: 

I guess it's meant that you enable gzip compression for your css and js files, cuz that will enable the client to receive both gzip-encoded content and a plain content.

This is how to do it in apache2:

<IfModule mod_deflate.c>
    #The following line is enough for .js and .css
    AddOutputFilter DEFLATE js css

    #The following line also enables compression by file content type, for the following list of Content-Type:s
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml

    #The following lines are to avoid bugs with some browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule>

EDIT: Here's how to add the Vary Accept-Encoding header: [src]

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>
aularon
I don't think this is it. My JS and CSS are already compressed. PageSpeed still complaining.
StackOverflowNewbie
I edited the answer, check it.
aularon
I think mod_deflate is [supposed](http://httpd.apache.org/docs/2.0/mod/mod_deflate.html#proxies) to send the Vary header by default.
Matthew Flaschen