best practices managing js obfuscated code?

T

tgh003

I would be interested to hear how others are managing their javascript
(.js) files from the original code vs the obfuscated version they
publish to their site/webapp.

I currently manage 2 files, and everytime i need to make a change, I
have to switch the names, test, then rename again, obfuscate to the
original file name (because this is the file referenced in php/perl/asp
whatever files). So its kind of a pain.

Any thoughts out there? Be very interested to hear how you are
managing your files.

Thx,
John
 
T

Thomas 'PointedEars' Lahn

I would be interested to hear how others are managing their javascript
(.js) files from the original code vs the obfuscated version they
publish to their site/webapp.

I do not obfuscate my code; as mentioned here before, it would be a
Bad Thing, e.g. because nobody could learn from it and easily reuse
it then. My local code (i.e. that is running on my local test server)
differs from public code in the respect that all JSdoc[tm] comments
have been removed from it. I currently make the commented versions
available in versioned subdirectories and short comments on top of
the "used" resources mention that. Maybe I will compact the "used"
code some time to save bandwidth and gain speed[1], but nothing more.


HTH

PointedEars
___________
[1] which is a two-edged sword: compacting code could introduce the
need for more statement delimiters than needed in uncompacted
code. I have yet to investigate that further.
 
L

Lee

(e-mail address removed) said:
I would be interested to hear how others are managing their javascript
(.js) files from the original code vs the obfuscated version they
publish to their site/webapp.

I currently manage 2 files, and everytime i need to make a change, I
have to switch the names, test, then rename again, obfuscate to the
original file name (because this is the file referenced in php/perl/asp
whatever files). So its kind of a pain.

Any thoughts out there? Be very interested to hear how you are
managing your files.

Sorry, but you're the only one who feels that hiding their code
is worth the effort.
 
R

Randy Webb

(e-mail address removed) said the following on 11/2/2005 5:38 PM:
I would be interested to hear how others are managing their javascript
(.js) files from the original code vs the obfuscated version they
publish to their site/webapp.

The only people who obfuscate code are the ones who lack the
understanding to realize it is a waste of time. Not only from the
obfuscating point of view, but, from the maintenance point of view that
you are experiencing.

I have not seen your code but I promise you. Nothing you have done is so
unique that it has not been done, or will be repeated, in the past or
future.
I currently manage 2 files, and everytime i need to make a change, I
have to switch the names, test, then rename again, obfuscate to the
original file name (because this is the file referenced in php/perl/asp
whatever files). So its kind of a pain.

Precisely why you *shouldnt* obfuscate code. Its a waste of time.
Any thoughts out there? Be very interested to hear how you are
managing your files.

I manage them by using one file. I edit it, I publish it, no problems.
 
T

tgh003

I didnt necessarily mean obfuscate, but perhaps compress (i.e. remove
comments, remove tabs, white space, etc....), this often saves 30%+ of
file size - which can make a big difference.

Just curious how people are managing their files.
 
V

VK

I didnt necessarily mean obfuscate, but perhaps compress (i.e. remove
comments, remove tabs, white space, etc....), this often saves 30%+ of
file size - which can make a big difference.

Then it's called "script squeezer" (old term) or "script compactor"
(newer term) and it's indeed a great tool for delivering big scripts to
the client-side (up to 70% compression).
 
K

Kevin Newman

I would be interested to hear how others are managing their javascript
(.js) files from the original code vs the obfuscated version they
publish to their site/webapp.

I currently manage 2 files, and everytime i need to make a change, I
have to switch the names, test, then rename again, obfuscate to the
original file name (because this is the file referenced in php/perl/asp
whatever files). So its kind of a pain.

Any thoughts out there? Be very interested to hear how you are
managing your files.

Thx,
John

I don't necessarily think of what I do with my code as obfuscation as
much as compression, but for the scripts at
http://www.unfocus.com/projects/FlashSuite/ - I develop using a folder
structure (that I got from an actionscript book - though I've seen it
elsewhere too) - I have a source folder, and a deploy folder (and some
others like an assets folder).

In the source folder I have all of the uncompressed javascript files
(and actionscript files, flas/swfs, etc.) commented all over (am in the
process of switching to JSDoc style comments), with each class in it's
own file, arranged in a namespace like directory structure.

In the deploy folder I have my html files (if I'm using the js classes
for a site) and the rest of the site folders (images folder scripts
folder, etc.). In the scripts folder, I have at least two files, one
that contains every js class that I intend to use for the site, just
copied in from the individual js class files (I usually call it
unFocusLib.js) and another js file with a -p on the end of the name
(like unFocusLib-p.js) which is just the large file compressed with Dean
Edward's packer tool (http://dean.edwards.name/packer/).

Active development on the js classes usually takes place in an html file
in the source folder, that links to all the individual class files. Then
the working code is just copied to the deploy folder, where the window
dressing is usually applied.

I'm not sure this is the best way, but it is the way I do it for now. :)

Kevin N.

P.S. I include a link in the compressed files to where you can get the
source code. There's no reason to hide anything.

P.P.S. I haven't released an updated package yet that reflects what I
described here, and am still refining that work process and directory
structure. ;-P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top