0

I want to compress all the Javascript and CSS files in my codebase,separately.

How can I do it right from the scratch using only YUI Compressor ? Solution with steps will be appreciable .

I need it for SVN windows machine. The setup should be such that when any developer runs two separate bat files(one for JS and other for CSS), the main files say min.js & min.css should get compressed.

Regards.

mmt
  • 161
  • 1
  • 2
  • 13
  • This question as-written doesn't have anything to do with SVN. Please clarify the question if it does or just remove the tag. – Patrick Quirk Oct 14 '14 at 12:56

1 Answers1

1

From this answer, use the YUI Compressor. It requires Java, but will run locally from a batch file and minifies both Javascript and CSS files.

Javascript:

java -jar yuicompressor-2.4.8.jar --type js yourfile.js -o yourfile.min.js

CSS:

java -jar yuicompressor-2.4.8.jar --type css yourfile.css -o yourfile.min.css

The download page is here.


To perform these steps on all files in a directory, put the following in a batch file (note it will not work on the command line):

for /f %%f in ('dir /b c:\*.js') do (
    java -jar yuicompressor-2.4.8.jar --type js %%f -o %%~nf.min.js
)

This minifies all files with a js extension and outputs the minified file to <filename>.min.js in the same directory.

Community
  • 1
  • 1
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88
  • Hi Patrick, Thanks. it works out perfectly :) Can you please tell me how do I do this for a folder having many JS files ? Such that, there should be one minified.js file which should have all the code of the files within the folder specified in minified file. Please help me on this . – mmt Oct 15 '14 at 05:19
  • Thanks alot Patrick ! That works fine and I am near to my implementation. The only thing remaining now is : 1. Is there any way by which I can mention in batch file to YUI compressor to compress all the files (files in the folder as well as subfolders) I have a hierarchy of 3-4 levels w.r.t Folders and subfolders and all of them consist only JS files ? 2. I want the output to be clubbed/merged into 1 single file and not separate files. How can I achieve this ? – mmt Oct 17 '14 at 09:21
  • 1. Look at the options for the `dir` command in the code I posted, there should be a "recursive" option. 2. Not sure, you'd be better asking that in a separate question. – Patrick Quirk Oct 17 '14 at 14:00