Phil Jackson
Phil Jackson

Reputation: 10288

jQuery compression leads to errors

could someone please explain when I have a jquery script which runs fine with no errors and then compress and upload it then returns errors?

Much appreciated.

EDIT The only error im getting using jsLint is:

Error:

Implied global: $ 3,25,27,28,31,32,34,35,36,38,45,46,47,49,50,61,63,64,65,67,71,75,79,83,87,91,94,95,96,98,101,102,103,111,113,114,115,121,123,124,125,127,130,131,132,142,144,145,146,147,148,149,150,151,152,153,154,155,171,173,174,175,177,180,181,182,192,194,195,196,197,198,199,200,201,202,214,216,217,218,220,223,224,225,234,240,241,242,243,244,245,246,247,248,249,250,251,253,254,255,256,257,258,259,260, window 7, alert 56,106,137,187,230, document 234

which is cause its in jQuery im guessing

Upvotes: 0

Views: 197

Answers (4)

Mottie
Mottie

Reputation: 86413

I'm not sure what you are using to compress your javascript, but I have noticed from using the Google Closure compiler that it doesn't following the "rules" per se.

Given this code:

var t = true;
if (t) { alert("it's true!"); }

which gives no errors in JSLint (except for "Implied global: alert 2")

If I compress it using the "who needs whitespace" setting, this is the result

var t=true;if(t)alert("it's true!");

which is of course optimized, but now gives a JSLint error.

Upvotes: 0

dave1010
dave1010

Reputation: 15415

An alternative to JSLint is JavaScriptLint. May be worth checking it in that too. What errors are you getting in the browser? Firebug for Firefox should give you more details of the error message.

Upvotes: 0

Ernelli
Ernelli

Reputation: 4040

Probably because you have errors in your script that does not cause any problems when the script is not compressed.

I recommend try using jslint on the script to verify that it is correct.

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382656

Most likely you are missing the statement terminator ; at some line(s), for example following code would run fine even if i don't specify that:

$(....).click(function(){
  .....
}) <-- // no `;` char here

Or even this:

alert('hello') <-- // no `;` char here

But when you compress it, and you have forgot to place that character somewhere, you will receive the errors.

Make sure this is not the case in your script other than any possible issue.

Upvotes: 1

Related Questions