Please add some minifier or packer script before the compression to gzip...
it would be great...

Thanks

CommentFileSizeAuthor
#3 YuiBatch.zip1.27 KBgremlinc5
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gremlinc5’s picture

because of the nature of smartcache, adding minifying could be difficult.

Best minifiers around (yui compressor by Julien Le Comte) are not written in php, so it would be tricky to implement them.

The best thing you can do is write a script that:
1 - connects to your site via ftp
2 - downloads every js and css file
3 - runs iteratively the compressor over them
4 - uploads the compressed files to your site

This way, every time you update your Drupal site, you can rerun your minifying script.

It's not that difficult (I did it once in a .bat file, but I can't find it anymore, sorry)...

I'll see if I can find it somewhere.

panji’s picture

yup,.. coz it would be so long if I should minified them every time I update the module, etc etc,.. and YUI Compressor can't be used as a compressor on the fly,.. what about other compressor like jsmin?

humm anyway, please let me know if You've found the .bat file

thanks

gremlinc5’s picture

FileSize
1.27 KB

JSMin is not that good, so I prefer to compress the production js files offline and reupload them.

GZipping js and css with or without JSMin-ifying them is not that different, so I did not bother to implement a possibly buggy minifyer.

In fact, it's a really hard topic, so I prefered to totally avoid it and stick with a simple and optimizable task (zip compression), rather than try to make a buggy minifyer no one would use.

About thje batch script, I think I lost it, but I found the minify part.
Attached you'll find an archive. Inside there is the bat file and the directory tree.

The batch file:

echo off
rem remove and create output directory
rmdir /S /Q Compressed
mkdir Compressed
rem copy subdirectories and .js files from in to out
xcopy /T /E "SourceFiles\*" "Compressed\*"
xcopy /S "SourceFiles\*.js" "Compressed\*.js"
xcopy /S "SourceFiles\*.css" "Compressed\*.css"
rem run recursive compression for js and for css files
set yuiexe="%CD%\yuicompressor.jar"
FOR /R Compressed %%i IN (*.js) DO java -jar %yuiexe% --charset utf8 -v -o "%%i" "%%i"
FOR /R Compressed %%i IN (*.css) DO java -jar %yuiexe% --charset utf8 -v -o "%%i" "%%i"
echo on
@pause

Basically it copies every js and css file from the SourceFiles folder to the Compressed folder, then calls yuicompressor iteratively on it.

There is no ftp part on this batch, so you'll have to manually copy your js files to the SourceFiles folder and reupload them.

Or use a tool like rsync and modify the batch accordingly. I can't do this myself at the moment, sorry.

Note that to setup this you have to copy the file yuicompressorxxx.jar into the YUIBatch directory AND RENAME it into yuicompressor.jar.

Hope it helps...

Bye

ibandyop’s picture

Perhaps you can integrate this PHP minifier. http://code.google.com/p/jsmin-php/ ( As an option for those who want to try )