Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

minifying / obfuscating JS files 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I was looking into obfusacating my JS files with but read that obfuscation can cause bugs and problems, so i then looked at simply minifying, with but there it says 'do not use raw control characters in strings'.

What's a 'raw control character' ?

Do they mean such things as 'Hi there\n' , isn't \n the correct way of adding a newline to a string in javascript?


I'm a bit confused over what is the best way forward and what i mignt need to do to my scripts to prepare them for processing.

Your guidance is appreciated.

Thanks,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
On a side note, what's the purpose of JSLint?

i ran one of my scripts through it and got a load of errors, the first was...
Problem at line 22 character 25: Expected exactly one space between ')' and '{'.

function member_update(){

Is it seriously trying to tell me that before the opening body of the function header there should be a space?

Is it to do with making it clear what forms the 'method signature'?

how does minfying JS and JLint get on?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
Control characters are commands that use the control key. The notation is usually the caret symbol plus a letter such as ^A .

Minify and Jlint are technically opposed so using one means you can't use the ther other. Why. Because Minify scrunches the code up to take up the least amount of space so all white space and unnecessary carriage returns etc are removed.

Jlint on the other hand checks syntax and "grammatical" Correctness of the code. It checks structure as well, so yes it is telling you it needs a space there for complete correctness.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
So you can't run it through lint prior to minifying?

Would you bother?

Do I just minify as the script is working or is there any recommendations that say your shouldn't minify?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
You can run it to make sure everything is correct before minifying it, but minifying will remove all spaces and unnecessary characters from the code so whatever additions you made by lint's suggestion will likely be removed by minifying.

If its working without any errors in all your target browsers, then you can go ahead and minify it without running it through lint.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
thanks Phil, much appreciated.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top