3

I am optimizing a magento store, and some JS and CSS (compiled and minified in a MEDIA folder) aren't being served gziped as they should.

All pages are gziped (ex. this HTML page) but some content isn't (ex. this JS file).

Testing via gtmetrix.com and whatsmyip's HTTP Compression Test

I have this config in .htaccess:

    <IfModule mod_deflate.c>

    # Insert filter on all content
    SetOutputFilter DEFLATE

    # Insert filter on selected content types only
    #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don't compress images
    #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

</IfModule>

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/js

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

What could I be missing?

Mat
  • 1,536
  • 1
  • 17
  • 21
MgtWizards
  • 139
  • 1
  • 1
  • 4

2 Answers2

2

You can use this in your .htaccess

# BEGIN Compress text files
<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>
# END Compress text files

This is the part of an example of .htaccess configuration leading to compression of all your *.css, *.js, *.html, *.xhtml, and *.php files listed here (http://www.samaxes.com/2009/01/more-on-compressing-and-caching-your-site-with-htaccess/). It is also listed there how to set up expires by type for headers and caching. But it is not so essential for you.

The other way to set up compressing is to use external extension module for apache mod_gzip. It is as well very popular solution. To use this solution you should write in your .htaccess this

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

For more detailed information, please, consult this article (http://www.samaxes.com/2008/04/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/).

Meriadoc Brandybuck
  • 1,300
  • 9
  • 11
1

I had the same problem, I was testing with Chrome 38.0.2125.104 (64-bit) Dev Tools analyzing the server response headers.

I think you should add this directive to your htaccess

AddOutputFilterByType DEFLATE text/javascript
nulll
  • 505
  • 1
  • 5
  • 8