JavaScript stops working when I compress my script

I want to compress my 2000+ javascript lines, and I tested as http://dean.edwards.name/packer/ and http://closure-compiler.appspot.com/home .

But in both cases the compressed script gives me errors. An example of an error is jQuery(document).Da is not a function.

Why is my script optimizer not working? And what can I do to optimize / compress my script?

+5
source share
3 answers

You can try the YUI online compressor. This is the first result on google: http://www.refresh-sf.com/yui/

+3
source

, JavaScript. Bizarre, , :

- :

function someFunc() {
   ...
}

( , jQuery):

(function($) {
   ...
})(jQuery);

:

function someFunc(){ }( function($){...} )(jQuery);

someFunc function($){...} . , , , jQuery .

jQuery ;(function($){.

( , ) :

;function someFunc(){ }; (function($){...})(jQuery);

, .

+6

I had the same problems. every time I wanted to minimize my javascript files, including several jquery plugins, I got an error. At first I tried to solve problems with extra semicolons, as explained by nikolaid in his last post. even with his advice, I could not minimize my js file without errors. after that I changed the next line in each jquery plugin and worked for me; eg:

(function($) {
$.fn.defaultInputs = function(settings) { ...

i simplified

jQuery.fn.defaultInputs = function(settings) { ...
0
source

All Articles