开发者

Javascript minification with semicolon insertion

开发者 https://www.devze.com 2023-01-27 02:45 出处:网络
Is there any Javascript minifie开发者_高级运维r/compressor which will insert semicolons as necessary (or, one which works with source code which doesn\'t use semicolons)? I\'ve started using a library

Is there any Javascript minifie开发者_高级运维r/compressor which will insert semicolons as necessary (or, one which works with source code which doesn't use semicolons)? I've started using a library which is really great, but the developer considers the semicolons as "unnecessary clutter"...


When I was in a similar situation a couple of years ago, I seem to recall that the solution was essentially "the more the merrier"!

Firstly I ran the script through Dojo Shrinksafe on very modest compression settings. Because it uses Rhino, it would actually interpret the JS and then write out an equivalent version with syntactically correct semicolons.

From there, I fed the output into Dean Edward's /packer/, which (at the time, at least) was the highest-compression library that produced consistently functional output. This library requires the input to have semicolons, but that wasn't a problem thanks to the output from ShrinkSafe.

(Note that this is from memory and I haven't tested it recently, but there's no reason why the principle shouldn't hold any more. If ShrinkSafe doesn't insert semicolons for you, perhaps there's some other JS-preprocessing tool that will automatically do this? Modulo, of course, the fact that semicolon insertion is not 100% deterministic).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号