Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsmin bails on extremely large libraries. #17

Closed
GoogleCodeExporter opened this issue Mar 15, 2015 · 4 comments
Closed

jsmin bails on extremely large libraries. #17

GoogleCodeExporter opened this issue Mar 15, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Hi, I've encountered problems with jsmin when using extremely large files, (ie 
prototype, 
scriptaculous et al) in one compression. I've previously been using a simple 
sequence of 
preg_replaces to flatten the js into one line. It might not through exceptions 
for errors in the 
javascript and if the javascript was not written 100% correctly, ie ; after 
nearly everything then 
the compressed javascript will not work. however there is a significant speed 
improvement and it 
might be worth implementing. as an options instead of using jsmin.

to implement the hack modify the function 'minifyJS' to below

  protected static function minifyJS($js) {
     return self::compressCode($js);
  }

then add the following function

  protected static function compressCode($code)
  {
    // Remove multiline comment
    $code = preg_replace('/\/\*(?!-)[\x00-\xff]*?\*\//', '', $code);
    // Remove single line comment
    $code = preg_replace('/[^:]\/\/.*/', '', $code);
    // Remove extra spaces
    $code = preg_replace('/\s+/', ' ', $code);
    // Remove spaces that can be removed
    $code = preg_replace('/\s?([\{\};\=\(\)\/\+\*-])\s?/', '\\1', $code);
    return trim($code);
  }



Original issue reported on code.google.com by bugged...@gmail.com on 28 Aug 2007 at 4:39

@GoogleCodeExporter
Copy link
Author

Original comment by rgr...@gmail.com on 28 Aug 2007 at 5:06

  • Changed state: Invalid
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

not quite sure why it is invalid. it's a perfectly valid point. a better 
alternative to jsmin and the pre mentioned 
script is http://joliclic.free.fr/php/javascript-packer/en/

Original comment by bugged...@gmail.com on 28 Aug 2007 at 9:15

@GoogleCodeExporter
Copy link
Author

JSMin doesn't "bail" on large libraries. The problem you're seeing is that 
Prototype,
Scriptaculous, and some other libraries are written with bad coding practices 
that
JSMin doesn't tolerate. The rule of thumb is that if JSLint throws warnings, 
you're
likely to run into problems with JSMin.

Packer is a reasonable alternative to JSMin, but whether or not it's better is
arguable. They both have their advantages and disadvantages.

I'd advise against using your regexp-based minification function. JavaScript is 
a
notoriously difficult language to parse correctly, and those regexps are 
absolutely
guaranteed to introduce errors (especially the 'remove extra spaces' regexp, 
which
doesn't take strings into account).

Original comment by rgr...@gmail.com on 28 Aug 2007 at 9:23

@GoogleCodeExporter
Copy link
Author

I believe I read someone now maintains JSMin-friendly versions of these 
libraries 
(or you can get pre-minified versions). Regardless, in version 2.x you can use 
the 
PHP5 Packer (or any other code) for certain files if you want. The 
configuration is 
a little tricky, but ask on the google groups.

Original comment by mrclay....@gmail.com on 27 Nov 2008 at 3:37

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant