Random bits ‘n’ pieces

John Reilly’s Blog

« PreviousNext »

Update to JSMin.java

21 August 2007

For anyone using JSMin.java, I’ve made a small update to JSMin.java to match with the latest jsmin.c. Thanks to Manuel Dominguez Sarmiento for pointing out the mismatch between the two.

Posted in javascript | Trackback | del.icio.us | Top Of Page

    9 Responses to “Update to JSMin.java”

  1. Adnan Memon Says:

    Can you list the changes done recently .. or is there any other location where I can see the changelog?

  2. John Says:

    Of course. There is a diff at http://www.inconspicuous.org/projects/jsmin/jsmin20070820.patch

  3. Adnan Memon Says:

    Thanks John.

  4. Richard Davies Says:

    One problem I’ve encountered with JSmin is that it strips Microsoft’s conditional compilation comments. I found a JavaScript version of JSmin that’s been modified to leave conditionial comments alone:
    http://tanny.ica.com/ICA/TKO/tkoblog.nsf/dx/jsmin-and-javascript-conditional-comments

    I tried porting the change over to your library, but I don’t know much about Java and couldn’t seem to get it to work. My code is available at the link below, with the changed lines highlighted. (The meat of the fix is around line 143.)
    http://pastebin.com/f4286507e

    Could you please take a look at this and see if you can get it to work? I’d really appreciate it. Thanks!

  5. Dave Says:

    Gentlemen,

    I was working on a client who had a version of your JSMin.java. For me it was not minifying CSS in away that allowed background-position to work with - numbers. Below are the modifications I made (in case anyone is still working on this project).

    The JSMin had the following header (the client has an old tech stack, java 1.3, so this is really the only minifier that works, YUI Compressor won’t cut it).

    /*
    *
    * JSMin.java 2006-02-13
    *
    * Updated 2007-08-20 with updates from jsmin.c (2007-05-22)
    *
    * Copyright (c) 2006 John Reilly (www.inconspicuous.org)
    *

    I went ahead and modified a line to allow for the background-position css property to contain negative numbers. Initially the JSMin would do this:
    background-position:-134px-43px;

    Which causes a CSS error. I added a line preceding line 218, and it looks like the below. You will notice I added a comment and an if(theB == ‘-’) action(1);

    public void jsmin() throws IOException, UnterminatedRegExpLiteralException, UnterminatedCommentException, UnterminatedStringLiteralException{
    theA = ‘\n’;
    action(3);
    while (theA != EOF) {
    switch (theA) {
    case ‘ ‘:
    //this allows for the background-position negative(-) px values to work
    if(theB == ‘-’) {
    action(1);
    } else if (isAlphanum(theB)) {
    action(1);
    } else {
    action(2);
    }
    break;
    case ‘\n’:

  6. Hemakumar Says:

    Can someone please help me how to use this jar in ant build script.

  7. John Says:

    @Dave - It’s not meant to minify css - it only works on javascript.

  8. John Says:

    @Hemakumar - I have not published a jar file - just add the java file to your project and modify it as needed. Personally I would recommend against using JSMin - I no longer use it, instead opting for the yui compressor. See http://developer.yahoo.com/yui/compressor/

  9. John Says:

    Apologies for the late replies - I only saw the comments in the approval queue now - I don’t remember getting any emails about them :(

Leave a Reply