JSMin+ version 1.1
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:
You can read more about JSMin+ in the announcement post.
update 14-04: added known issues summary to this post.
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
- JScript conditional compilation support is not complete yet
You can read more about JSMin+ in the announcement post.
update 14-04: added known issues summary to this post.
04-'09 JSMin+ version 1.2
04-'09 A new javascript minifier: JSMin+
Comments
http://tweakers.net/meuktracker/ 
Maar goed bezig joh! Denk je er wel aan even achter je PC uit te kruipen en paaseitjes te gaan zoeken komende dagen?


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


Oh zitten er ook easter eggs in ja? Te gek, daar gaan we naar zoeken.
Does this script also simplify vars,parameters and function names?
Like function GetImage(imageID) becomes function Fun1(p0)
Like function GetImage(imageID) becomes function Fun1(p0)
@leon: No this script would not obfuscate the javascript files as this could break any inline javascript calls.
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.
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.
@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.
Anyway I like your script, although I can't use it with my projects.
leon, simple example:
JavaScript:
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 maandag 13 april 2009 15:27]
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:
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.
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 maandag 13 april 2009 15:52]
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:
the optional filename parameter is used for the reporting of parse errors, nothing else.
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.
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...Odd that this is not documented on the UBB faq which is linked right under this editing box.
[Comment edited on maandag 13 april 2009 17:37]
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?
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...
@crisp, ahh the WITH statement, it gave me the goose bumps all over again. Had so much problems with them in the past.
@crisp: I'm running PHP 5.2.9-1
My setting is:
error_reporting = E_ALL & ~E_NOTICE
My setting is:
error_reporting = E_ALL & ~E_NOTICE
Vordreller: did you check if your $script has any content, and if $minified has content after calling minify?
Yes, I checked it. I debug PHP using Netbeans 6.5.1
Here's a simple Javascript file I have:
JavaScript:
$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.
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 zaterdag 18 april 2009 16:08]
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).
Am I right in understanding JSMin+ only minifies pure js files and not html?
Kirk: yes, that's right
Comments are closed