0

I have a function:

    function createAddressList(url) {
        $.ajax({
            url: url,
            cache: false,
            async: true
        }).done(function (msg) {
            alert("Data Saved: " + msg);
        });
    }

which translates minified to:

function g(b){a.ajax(http://localhost/testpage/b,cache:!1,async:!0).done(function(a){alert("Data Saved: "+a)})}

this results in an error,

chrome :

Uncaught SyntaxError: Unexpected token :

Firefox:

SyntaxError: missing ) after argument list
...ion g(b){a.ajax(http://localhost/testpage/b,cache:!1,async:!0).done(f

How can I solve this? Help is much appreciated

Nealv
  • 6,856
  • 8
  • 58
  • 89
  • My suggestion would be to run the JS without uglifying it and see if you come across any errors in the console. – jonsuh Oct 02 '14 at 15:04
  • Well the minified code is totally broken. Report it as a bug. Even if your code is wrong, Uglify should at least report an error and not produce worse code. – jgillich Oct 02 '14 at 15:18
  • Without minification, everything works – Nealv Oct 02 '14 at 19:51

1 Answers1

-1

Use mangle option to make exceptions when renaming $ to jQuery:

1) Use jQuery instead $

function createAddressList(url) {
        jQuery.ajax({
            url: url,
            cache: false,
            async: true
        }).done(function (msg) {
            alert("Data Saved: " + msg);
        });
    }

2) Config Uglify

grunt.initConfig({
  uglify: {
    options: {
      mangle: {
        except: ['jQuery']
      }
    },
    my_target: {
      files: {
        'dest/output.min.js': ['src/input.js']
      }
    }
  }
});
Martín Alcubierre
  • 4,341
  • 1
  • 27
  • 27