0

I'm trying to speed up my Magento store and have recently enabled Gzip compression. The problem is, i also use the Magento in-built function that merges all CSS and JS files together to serve a single file for each.

The Gzip does not compress those files & since this is Magento, those files are enormous and slow down the site significantly.

Anything i can do that Gzip will also compress those files? They are located in /media/js/ and /media/css/

Edit: using mod_deflate, right now i have it set to this:

<IfModule mod_deflate.c>

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:pdf|doc)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp3|mp4|rm)$ no-gzip dont-vary

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
Teekay
  • 163
  • 3
  • 10
  • Are you really sure those files slow down your site? If caching is configured correctly, those resources should be requested only once by each client. – Pekka Dec 08 '11 at 20:12
  • 1
    Check out fooman speedster. Awesome extension that handles all of this for you. – Tom Dec 08 '11 at 20:28
  • mod_deflate should compress all content, even the php-generated ones. Is magento sending the correct MIME headers for css and js? – Gerben Jan 14 '12 at 22:08

3 Answers3

3

When Magento merges any CSS and Javascript files that pass through its rendering system, it will create URLs for those resource like this, and add them to the head of the page

http://magento1point6point1.dev/media/css/a438f0287fdd0c52d9bd196d355a63c3.css
http://magento1point6point1.dev/media/js/0567fb98ebe279ea4faf5acf433fc6a1.js

in turn, this will generate files on the filesystem

media/css/a438f0287fdd0c52d9bd196d355a63c3.css
media/js/0567fb98ebe279ea4faf5acf433fc6a1.js

At this point, Magento is removed from the process almost completely (there's a RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ in .htaccess to catch non-existant files). It sounds like you have gzip compression setup correctly for other areas of the site. So, however you've configured other folders for gzip compression, configure media/css and media/js to do the same.

Without more information, it's impossible to debug your system further.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • Thanks. Edited my first post to provide some more info, attached my htaccess file excerpt, using mod_deflate to compress, but don't know how to include that directory to also be compressed. – Teekay Dec 09 '11 at 00:43
  • @SarthakGupta If you'd used 5 question marks someone might have been able to help. With only three I don't think we'll be able to solve it. – Alana Storm Oct 25 '12 at 16:48
  • The site I am working on is collectorsheritage.com . I am using HTTP live headers to assess the compression (if any). While the html files are getting compressed the same is not happening with my merged js and css files. Another important thing is I have fooman Speedster module installed and running already. – Sarthak Gupta Oct 26 '12 at 05:15
  • Hi @AlanStorm I am trying to understand this correctly. In the last bit of your reply "It sounds like you have gzip compression setup correctly for other areas of the site. So, however you've configured other folders for gzip compression, configure media/css and media/js to do the same." What do you mean by that exactly? I thought setting DEFLATE in root would count for all filetypes in any directory (under root). Thanks!! Can you elaborate a little? – snh_nl Feb 25 '13 at 18:57
  • can someone elaborate on what is needed here? My YSlow indeeed confirms that the media/*/js and media/*.css are not being gzipped .... but how to tell htaccess to gzip these two? – Luke Barker May 21 '13 at 18:14
  • I ran into this issue as well running Magento under LiteSpeed server which is a derivation of Apache provided by my hosting provider. mod_deflate was correctly set up but it did not work with merged js files (it worked ok with css). What did the trick was renamint media/.htaccess to a.htaccess (disabling it), reloading the page and then again renaming it back to .htaccess . Don't ask. – barbazul Sep 12 '13 at 20:40
  • @barbazul Thanks for the tip! Sounds like LightSpeed has a version of `.htaccess` stuck in its internal cache. – Alana Storm Sep 12 '13 at 21:13
0

For anyone experiencing the same issue: First try to refresh your browser cache.

Google Chrome PageSpeed Insights was telling me that the merged css and js files of my Magento store were not compressed, although I had GZIP enabled and configured .htaccess correctly.

After clearing the Chrome browser cache those merged files were compressed too, according to PageSpeed Insights. I guess some old uncompressed files were served from the browser cache...

MatthijsIJ
  • 101
  • 3
0

You can use Apache's http://httpd.apache.org/docs/2.0/mod/mod_deflate.html module.

Alex
  • 32,506
  • 16
  • 106
  • 171
  • Thanks, im already using it, edited my first post to add the excerpt from .htaccess, i just don't know how can i include files from /media/css/ and /media/js/ to also be compressed. – Teekay Dec 09 '11 at 00:46