.min.js does not redirect to .min.js.gz in some Apache configurations

cbas@pandion.be - July 12, 2009 - 13:00
Project:Javascript Aggregator
Version:6.x-1.2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

After installing and enabling the module I found that my browser (FF3.5+Firebug+PageSpeed) does not receive the JSmin+GZip version from the cache. Is this just me or is the module not working for anyone else either?

It seems the .htaccess file is set up for .js -> .gz files, but the code generates a cache of .jsmin.gz files so Apache won't find the GZip cache.

Also, the $footer output contains references to the .jsmin files which is just wrong as the .htaccess directives don't even look at that. In fact the .jsmin files should be removed as it's only an intermediate step and simply wastes disk space.

Fixed javascript_aggregator.module:

104-105;

        if (!file_exists($aggregated_file .'.gz')) {
          file_save_data(gzencode($contents, 9), $aggregated_file .'.gz', FILE_EXISTS_REPLACE);

138:
    //$scripts = str_replace($aggregated_file, $jsmin_file, $scripts);

#1

netsensei - July 12, 2009 - 18:08

Turned this into an actual patch against DRUPAL-6--1 in CVS. Patch attached. Needs testing.

AttachmentSize
javascript_aggregator_516882.patch 1.29 KB

#2

guix - July 17, 2009 - 15:04
Title:Wrong compressed file name for cache, wrong script file name in footer» .min.js does not redirect to .min.js.gz in some Apache configurations
Priority:critical» normal
Status:active» needs work

You are gzipping the aggregated file and sending the aggregated.js.gz, not the aggregated and minified file which is better. Anyway, it's a server configuration problem, see http://drupal.org/node/290280#comment-1392934

On localhost, I had this problem with the module (and that's why I came here), but on the production server, the module works fine.

#3

derjochenmeyer - July 22, 2009 - 22:21
Status:needs work» postponed (maintainer needs more info)

#0 All your patch does is to bypass the JSMin minification. That makes no sense.

Check the screenshot. After enabling javascript_aggregator AND (!) clearing the browser cache (!) YSlow hands out a B on "compress components with gzip"

The css file is the only one which is not gzipped.

AttachmentSize
YSlow-javascript_aggregator.png 26.56 KB

#4

kentr - October 29, 2009 - 08:15

@#0:

Like #3 said, do some more testing, clear site & browser caches, refresh... Didn't work for me first time around either but finally it did.

In fact the .jsmin files should be removed as it's only an intermediate step and simply wastes disk space.

From reading the GZip CSS issues, my understanding is that the non gzipped version has to remain for browsers that don't support gzip. .htaccess is supposed to test and only rewrite for browsers that support it.

It seems the .htaccess file is set up for .js -> .gz files, but the code generates a cache of .jsmin.gz files so Apache won't find the GZip cache.

RewriteRule ^(.*)\.js $1.js.gz [L,QSA]

Looks to me like any *.js file is supposed to rewrite to *.js.gz. That includes xxx.jsmin.js. According to the GZip CSS project, on some servers you have to put the rules in the main .htaccess rather than in a per-directory .htaccess. Maybe your server is one of those. Try placing the rewrite rules in your main .htaccess.

Servers also handle rewrite rules differently (at least for me, who may very well be writing crappy rewrite rules). Could be that the rule just doesn't work for your server.

 
 

Drupal is a registered trademark of Dries Buytaert.