views:

37

answers:

4

Hi, 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

+1  A: 

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.

Sarfraz
I have checked that ( ran into that problem before ) firefox throws; `missing ) after argument`
Phil Jackson
sorry found it, made a typeo `' };`
Phil Jackson
@Phil Jackson: That's good news then :)
Sarfraz
argh still getting it
Phil Jackson
+1  A: 

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.

Ernelli
thanks nice tool, what is meant by `Problem at line 88 character 38: Unescaped '-'.if( to.search( /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[...`??
Phil Jackson
A: 

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.

dave1010
A: 

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.

fudgey
What i've found is that the compressors didn't add the ';' on the end of the compressed file. I just added one and it now works fine. Thanks all that replied.
Phil Jackson