JSMin+ version 1.1

By crisp on Sunday 12 April 2009 01:11 - Comments (18)
Category: JSMin+, Views: 10.158

Version 1.1 of JSMin+ is available for download. This version has improved performance and fixes some issues. If you use labels in your javascripts you are strongly adviced to use this version to re-minify your scripts.

Changelog:
  • Improved tokenizer performance by reading smaller chunks for matching
  • Bugfix: jumplabels for break/continue statements were not written to output
  • Improved stringmatching: cases like '\' and '<newline>' now throw unterminated string literal error
  • Fixed linenumber offset bug caused by JScript conditional compilation blocks
  • nest() always calls Statement() so no need to use call_user_func() with a parm
Known issues:
  • JScript conditional compilation support is not complete yet
The latest version is available on http://files.tweakers.net/jsminplus/jsminplus.zip

You can read more about JSMin+ in the announcement post.

update 14-04: added known issues summary to this post.

Volgende: JSMin+ version 1.2 04-'09 JSMin+ version 1.2
Volgende: A new javascript minifier: JSMin+ 04-'09 A new javascript minifier: JSMin+

Comments


By Tweakers user RobIII, Sunday 12 April 2009 02:11

http://tweakers.net/meuktracker/ :Y)

Maar goed bezig joh! Denk je er wel aan even achter je PC uit te kruipen en paaseitjes te gaan zoeken komende dagen? ;) :>

By Tweakers user Cyphax, Sunday 12 April 2009 10:15

Oh zitten er ook easter eggs in ja? Te gek, daar gaan we naar zoeken.

By leon, Sunday 12 April 2009 10:36

Does this script also simplify vars,parameters and function names?
Like function GetImage(imageID) becomes function Fun1(p0)

By Tweakers user Erkens, Sunday 12 April 2009 11:39

@leon: No this script would not obfuscate the javascript files as this could break any inline javascript calls.

By Tweakers user crisp, Sunday 12 April 2009 23:04

leon: I explained in my previous post on JSMin+ that even though that form of munching/obfuscating will give you better results in terms of even smaller sizes, it does have a certain risk and cannot be applied to every valid script.

I myself don't want to be bound by very rigid constraints when it comes to javascript development. I don't want to think about having to include a semicolon after every single statement, having to use curly braces for every conditional statement, having to refrain from using pre- or postfix increments/decrements combined in a larger expression and having to use JSLint after every change. That's just counter-productive, and that's why JSMin+ doesn't have any of those limitations that most other minifiers do have.

If I were to introduce abbreviation of function and variable names, which technically wouldn't be so hard because the parser stores a list of all of the declarations and the used scope, I would again be limiting myself in using the expressive nature of javascript. It would mean that you always have to use explicit references and all of those references would have to be confined to the same scriptfile.

By leon, Monday 13 April 2009 14:31

@crisp: You're right about the function names, but function parameters and variabels can be simplified, without that much of a hassle.

Anyway I like your script, although I can't use it with my projects.

By Tweakers user crisp, Monday 13 April 2009 15:27

leon, simple example:

JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
function something()
{
    var blaat = 'moeh';

    with (myObject)
    {
        // wether this is a reference to the local variable 'blaat'
        // or a property 'blaat' of myObject depends on the
        // runtime definition of myObject!
        alert(blaat);
    }
}

[Comment edited on Monday 13 April 2009 15:27]


By Tweakers user Vordreller, Monday 13 April 2009 15:50

I can't get this to work the way it's stated it should work.

I get no feedback whatsoever and the filecreation doesn't seem to work.

Here's an example of what I had to do to generate the new file anyway:

(I downloaded the example javascript found on the Tweakers post):

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
require 'jsminplus.php';

  $filename = "C:\\wamp\\www\\JSMinPlus\\general.js";
  $handle = fopen($filename,"r");
  $script = fread($handle,filesize($filename));
  fclose($handle);
  $filename2 = "C:\\wamp\\www\\JSMinPlus\\result.js";
  //$filename2 is not automatically created by JSMinPlus.
  $minified = JSMinPlus::minify($script , $filename2);
  $handle2 = fopen($filename2,"a");
  fwrite($handle2,$minified);
  fclose($handle2);



Are code tags even supported? Only one way to find out...
EDIT: code tags are supported... how can I input which language I'm using? And is this useable on the main tweakers site aswell?
EDIT2: "code=php" did the trick. Odd that this is not documented on the UBB faq which is linked right under this editing box.

[Comment edited on Monday 13 April 2009 15:52]


By Tweakers user crisp, Monday 13 April 2009 17:37

Vordreller: which version PHP are you using? The script will not work on PHP4.

Have you tried with error_reporting set to E_ALL? Do you get any errors then?

And instead of using fwrite it's easier to just use file_get_contents and file_put_contents ;)

As for
PHP:
1
//$filename2 is not automatically created by JSMinPlus.

the optional filename parameter is used for the reporting of parse errors, nothing else.
Odd that this is not documented on the UBB faq which is linked right under this editing box.
That faq is indeed a little outdated but it also mainly focusses on the frontpage reaction system. Support for [code]-tags is limited to the blogs and our forum. The forum UBB faq is more accurate but also mentions tags that are not usable here. It's something that needs attention but we haven't got around to that...

[Comment edited on Monday 13 April 2009 17:37]


By Tweakers user Spixo, Monday 13 April 2009 20:26

Waarom wordt eigenlijk wel de javascriptcode van Tweakers.net door een minifier gehaald? Maar de pure HTML-code niet? Ik denk eerlijk gezegd dat daar meer winst op te behalen valt dan op de javascript code?

By Tweakers user crisp, Monday 13 April 2009 22:35

Ricardo87: grote delen van de Tweakers.net frontpage code zijn wel degelijk minified, net als het forum. De delen die niet minified zijn zijn over het algemeen dynamische delen die niet statisch gecached kunnen worden. Voor die delen zou het betekenen dat we voor elke view on-the-fly minificatie moeten doen hetgeen weer extra processing tijd aan de serverkant kost...

By leon, Tuesday 14 April 2009 08:33

@crisp, ahh the WITH statement, it gave me the goose bumps all over again. Had so much problems with them in the past.

By Tweakers user Vordreller, Tuesday 14 April 2009 12:49

@crisp: I'm running PHP 5.2.9-1

My setting is:
error_reporting = E_ALL & ~E_NOTICE

By Tweakers user crisp, Tuesday 14 April 2009 13:20

Vordreller: did you check if your $script has any content, and if $minified has content after calling minify?

By Tweakers user Vordreller, Saturday 18 April 2009 16:08

Yes, I checked it. I debug PHP using Netbeans 6.5.1

Here's a simple Javascript file I have:

JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function escapeHTML(str) {
    var div  = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
}

function unEscapeHTML(str) {
    var div       = document.createElement('div');
    div.innerHTML = str.replace(/<\/?[^>]+>/gi, '');
    return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
}

function isInteger(value){
   return (!(value % 1));
}



$script had this as content and minified had the actuall minified code as content. So I can see it when debugging and offcourse, when opening the resulting file.

[Comment edited on Saturday 18 April 2009 16:08]


By Tweakers user crisp, Saturday 18 April 2009 17:35

Vordreller: so than it works as intended. Your expectation that the filename parameter means that the result will be written to that file is false; it's just an argument used for parse errors (e.g. when you're feeding a lot of JS files in one run it's easier to tell which file had a problem).

By Kirk Olson, Tuesday 2 February 2010 10:19

Am I right in understanding JSMin+ only minifies pure js files and not html?

By Tweakers user crisp, Tuesday 2 February 2010 10:22

Kirk: yes, that's right

Comments are closed