• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[Javascript] Minify code - special html characters problem


Well-known member
Just a quick feedback about script minifier. The one I using the most is the online service JsCompress (I've tried others but they didn't work well). This minifier is very good but still have an annoying bug: it will automatically convert special html characters (see issue).

http://www.shrinker.ch/ has also this problem

For example, this code
            string = string
                .replace(/&/g, "&")
                .replace(/&lt;/g, "<")
                .replace(/&gt;/g, ">")
                .replace(/&quot;/g, '"')
                .replace(/&#039;/g, "'");
            if(options == 'space')
                string = string
                    .replace(/    /g, '\t')
                    .replace(/&nbsp;/g, '  ')
                    .replace(/<\/p>\n<p>/g, '\n');
will give this:
string=string.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/&#039;/g,"'");if(options=="space"){string=string.replace(/    /g,"    ").replace(/ /g,"  ").replace(/<\/p>\n<p>/g,"\n")}
... which is not correct. So if one of your script uses those characters, do not minify it (unless you want to manually fix it).

The online service is using UglifyJS script which has been updated last week to version 2.0 (beta). So may be this bug will be corrected soon.