The eclectic musings of a bitter software engineer.

A faster JSMin library for PHP

Friday May 04, 2007 @ 09:19 PM (PDT)

I wasn't happy with the performance of the existing PHP port of JSMin, so I wrote my own implementation, which is significantly smaller and faster. This new library will be included in the next release of Minify, and you're welcome to download it and use it in your own projects:

require 'jsmin.php';

// Output a minified version of example.js.
echo JSMin::minify(file_get_contents('example.js'));

Comments

Oh neat, I started checking out minify when I saw your post on wednesday but haven't put it into use yet. Thanks on bringing awareness to that while making it work better.

Saturday May 05, 2007 @ 09:14 PM (PDT) Posted by Travis Pulley
Thanks for this script...I was using jsmin but I am going to give this a try and see how things work out.

Unfortunately I'm on PHP 5.2.0 (0.0.1 versions away, *cries*) so when I used minify the response I got from the server was...

"Call to undefined function sys_get_temp_dir()"

This function seems to be supported as of PHP 5.2.1...reading the manual comment for this page suggested that it is possible to create this function...

Check here for details...http://us2.php.net/sys_get_temp_dir

Prob not best workaround to add this to the start of the minify file but just for experiementing with it before I upgrade seems to work ok.
Thursday May 17, 2007 @ 04:37 AM (PDT) Posted by Carlton Dickson

Strict Standards: Redefining already defined constructor for class JSMin in jsmin-1.0.1.php on line 167

Thursday May 31, 2007 @ 12:00 AM (PDT) Posted by André Fiedler

I've released version 1.1.0, which fixes the error. Thanks.

Friday June 01, 2007 @ 10:30 AM (PDT) Posted by wonko

What about IE conditional comments ?

/*@cc_on

if ( @_jscript_version == 5.6 )

document.execCommand("BackgroundImageCache", false, true);

@*/

Sunday June 10, 2007 @ 02:28 AM (PDT) Posted by Laurent

At the moment, conditional comments are clobbered. That's because this is a direct port of Doug Crockford's jsmin.c, which does the same thing.

I don't intend to change the default behavior to be different from jsmin.c, but I'll consider adding an option not to remove conditional comments.

Sunday June 10, 2007 @ 10:21 AM (PDT) Posted by wonko

Hello,

Thanks for the port into PHP5 and its simple usage. I looked at the source but don't think there is an option switch to further remove the newlines

Saturday January 26, 2008 @ 10:18 PM (PST) Posted by Son Nguyen
Post a comment

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile or Markdown.

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Copyright © 2002-2008 Ryan Grove. All rights reserved.
Powered by Thoth.