JavaScript CSS – How to Gzip Merged JS

.htaccesscssgzipjavascript

Yes, I've read Alan Storm's suggestion, but I can't really call it a solution. My Gzip compression is configured correctly, only the merged css and js files aren't compressing (according to Google PageSpeed Insights). Does anyone have a solution?

The linked suggestion also notes that you should configure Gzip for the media/css and media/js folder too. I don't really understand this, because those files seem nowhere excluded from the global Gzip htaccess rule (Magento rule which is commented by default.)


edit: additional information:

Gzip

gzip compression => enabled

Zlib

zlib.output_compression => Off => Off
zlib.output_compression_level => -1 => -1
zlib.output_handler => no value => no value

.htaccess

<IfModule mod_deflate.c>

############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

# 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>

Response headers merged JS file 1 (Magento core JS)

Accept-Ranges: bytes
Connection: Keep-Alive
Content-Length: 547528
Content-Type: application/javascript
Date: Fri, 10 Jul 2015 09:51:35 GMT
Etag: "23f7c0-85ac8-51a6e0082dfbb"
Keep-Alive: timeout=1, max=100
Last-Modified: Thu, 09 Jul 2015 09:37:20 GMT
Server: Apache
Vary: User-Agent

Response headers merged JS file 2 (skin JS)

Connection: Keep-Alive
Date: Fri, 10 Jul 2015 09:53:04 GMT
Etag: "23f7c4-2ef94-51a6e00835cbb"
Keep-Alive: timeout=1, max=99
Server: Apache
Vary: User-Agent

Best Answer

Change this .htaccess line:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

to:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript text/x-js application/x-javascript application/javascript

and it should compress the merged js/css files. If you look at the "Content-type:" line in your headers, it shows:

Content-Type: application/javascript

which does not match the generic AddOutputFilterByType.

Related Topic