Hi Guys,
I am working on relatively medium to enterprise size project where we have 70+ javascript and 20+ css files plus libraries we use. I had this problem where I just want to minimize all files at once or individually using YUI compressor and Google Closure.
I couldn’t find anything that utilizes both and do compression without making API calls.
Thus I end up developing jcmin for myself which mean Jaspreet Chahal’s a Monster 🙂 Just kidding. It actually means Javascript CSS Minimizer
I didn’t do anything fancy I thought this util can help someone who want simple command line rather than remembering all the little things provided by individual compilers.
jcmin is in Beta. Not the actual compilers (Closure and YUI Compressor) but jcmin.
Important: jcmin is not a compiler itself.
You can say jcmin is a wrapper to YUI compressor and Google Closure and it only does basic stuff. I can add more Advance things if you like this util and want more control. As I said I developed this util for myself and I am kinda sharing it. If you end up finding it useful then consider donating or atleast a backlink to this page will much appreciated.
Pre-requisites
- .NET Framework >= 2.0
- Recommended: java.exe in System environment path.
Advantages of using this util
- Gives you option to choose between Google Closure and YUI Compressor
- You can minimize files under your directories
- You can even re curse through your directory and minimize files inside subdirectories. This util will form an equivalent structure at target directory.
- No need to goto separate compilers for Javascript and CSS this util do it both by firing appropriate compiler for a given file type.
- See Errors thrown by respective compiler.
- Comes with IKVM so if you dont have java installed compilers still work (I recommend to install it and put java.exe in Environment Path)
- You can skip any number of file by their name or even part of their name. so -excl=jque|ext will skip file names that contains jque and ext
- I am tired of typing this stuff, you will find out what Disadvantage you will come up with, so there is no point highlighting the advantages 🙂
Advertisement
Compilers used
- Closure
- YUI compressor (when you select switch -use=yui Closure will not be used)
- Closure Stylesheets
Interesting reading(s)
Problems and Solutions
Downloads
If you have java.exe in Environment Path | If you don’t have java.exe. Build comes with IKVM. |
Download | Download Recommended: Get Java Runtime Environment and put java.exe in Environment Path variable |
Support me, well I know you won’t but its worth asking because I’ve got pending bills for bandwidth that I use :).
Command options
Lets see what this command line util is capable of.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
shell> jcmin -source=PathToSourceJsFileDirectory -target=TargetDirectoryToStoreMinifiedFiles [options] ---options--- -v verbose mode ->default is off -dnam do not add `.min` in target file names -recursive Recursive search directory for .js and .css files -use possible values yui|google, default is Google Closure -excl exclude files, e.g. switch -excl=jquery|ext-all|jquery-ui... All the files that are mentioned will be excluded from minification. -autf8 avoid UTF-8. Applies to YUI compressor. By default this value is true -help print Usage help TIP: when you specify -source or -target folders DO NOT put a trailing \ at the end. e.g. -source=""c:\demo\"" is wrong -source=""c:\demo"" is right. TIP: When using recursion DO NOT put target folder as something inside your Source folder. so -source=""c:\demo"" -target=""c:\demo\output"" is wrong. There are obvious reason why this is bad. I'll leave it to you to find out why that is a bad Idea. |
Things you should know
- Default encoding type for YUI compressor is UTF-8. Use –autf8 to avoid it.
- When you minimize CSS with Google Closure following options are used by default
- –allow-unrecognized-functions (this is to avoid errors when CSS functions such as scale are used )
- –allow-unrecognized-properties (this is to avoied error when non standard CSS rules are used)
Reason: Well I included those function and properties for a reason in my CSS file with side effects known so why do I need to see my CSS not getting minimized because of that.
Future versions (If you guys support this Util): Will give you control on passing such flags to the individual compilers.
Advertisement
Advanced Usage
Each compiler comes with some advanced options. I am keeping this version as simple as I possibly can. If you think an option can be added to this command either contact me directly through contact form or leave you comment.
Disclaimer
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
So bottom line is that I am not responsible for any damage you may cause to your files. It is always a good idea to backup your files to be on safe side.
I rushed through this post, so if you see any spelling mistakes please let me know
Cheers!
Leave a Reply