1. 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

Discussion in 'General PHP and MySQL Discussions' started by cclaerhout, Sep 16, 2012.

  1. cclaerhout

    cclaerhout 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).

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

    For example, this code
    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:
    Code:
    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.
     
    Jake Bunce likes this.
  2. cclaerhout

    cclaerhout Well-Known Member

    Jake Bunce likes this.
  3. cclaerhout

    cclaerhout Well-Known Member

    A quick update. If you want a good minifier on your Windows local installation, just download the Microsoft Ajax Minifier and, if you want, download also an user interface like AjaxminGui. Works great and the compression is little better than the script used by JsCompres.
     

Share This Page