saquery.com
a web developer' s kung fu…
Compress all js and css files in a folder with yuicompressor

Just improved my scripts to compress Cascading Stylesheet and Javascript code with yuicompressor. I wrote 3 small MS Dos batches to compress all files in a specified folder. By executing _make.bat the script will compress all *.js and *.css files from a folder named "/src_debug/" to "src". Last but not least the script will store a log file for each compressed file in the source folder. The scripts are tested on Microsft Windows Vista.

I publish the scripts under GNU GPL

File: _make.bat Invokes a complete compression - Customize this file to your needs.
@echo off
 
set folder=%cd%\ 
call %folder%_compress_folder.bat %folder% c:\myproject\src_debug\ c:\myproject\src\
File: _compress_folder.bat Invokes the compression of a specified folder (*.js and *.css)
echo ***********************
echo Working on %2 
echo **********************
for %%f in (dir/s "%2\*.*") do (
	if %%~xf==.js (
		call %1_compress.bat %1 %2 %%~nf %%~xf js %3
	) else (
		if %%~xf==.css (
			call %1_compress.bat %1 %2 %%~nf %%~xf css %3
		)
	) 
)
File: _compress.bat Invokes the compression of a specified file with log-message output.
echo **********************
echo %3%4 [%5] TARGET: "%6"
echo SourceFile: "%2%3%4"
echo TargetFile: "%6%3%4"
echo ***
cd %2

call java -jar %1yuicompressor-2.4.6.jar --charset utf-8 --type %5 -v -o "%6%3%4" "%2%3%4">"%2%3%4.log"  2>&1

cd %1

Vote this page

Leave a Reply