Note that there are some explanatory texts on larger screens.

plurals
  1. POUglify-js doesn't mangle variable names
    text
    copied!<p>Trying to prepare good build environment for my js library. According to reviews on the web <a href="https://github.com/mishoo/UglifyJS" rel="noreferrer">UglifyJS</a> seems to be one of the best compressing modules out there, working under NodeJS. So here is best recommended way of minifying the code:</p> <pre><code>var jsp = require("uglify-js").parser; var pro = require("uglify-js").uglify; var orig_code = "... JS code here"; var ast = jsp.parse(orig_code); // parse code and get the initial AST ast = pro.ast_mangle(ast); // get a new AST with mangled names ast = pro.ast_squeeze(ast); // get an AST with compression optimizations var final_code = pro.gen_code(ast); // compressed code here </code></pre> <p>As seen here, <code>pro.ast_mangle(ast)</code> should mangle variable names, but it doesn't. All I get out of this pipe is javascript code, with no spaces. At first I thought that my code was not optimized for compression, but then I tried it with <a href="http://closure-compiler.appspot.com/home" rel="noreferrer">Google Closure</a> and got quite a compression (with mangled variable names and everything). </p> <p>UglifyJS experts, any hint to what I'm doing wrong?</p> <p><strong>UPDATE</strong>:</p> <p>Actual code is too large to reference here, but even a snippet like this doesn't get mangled:</p> <pre><code>;(function(window, document, undefined) { function o(id) { if (typeof id !== 'string') { return id; } return document.getElementById(id); } // ... /** @namespace */ window.mOxie = o; }(window, document)); </code></pre> <p>This is what I get (only spaces get stripped I guess):</p> <pre><code>(function(window,document,undefined){function o(id){return typeof id!="string"?id:document.getElementById(id)}window.mOxie=window.o=o})(window,document) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload