Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Re: Re: Re: Compressing/Obfuscating a Javascript file

by tachyon (Chancellor)
on Oct 10, 2001 at 07:55 UTC ( [id://117923]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Compressing/Obfuscating a Javascript file
in thread Compressing/Obfuscating a Javascript file

Herein you strike the basic problem. To do this correctly you need a complete tokenisation/lexical analysis. As even Netscape and M$ do not agree on what constitutes valid code this is an interesting task. However I am not interested :-)

If you are happy that a function definition will generally start on a line by itself then option 2 is the go. This will leave named nested functions alone which would not seem to be a major deal. You either make a compromise and be happy that you can parse a say 99% subset of all legal code with a simple rules based system or you get the sourcecode of a javascript interpretter, and hack into the guts of it.

I once wrote some code to strip the comments out of Perl code and condense it down. It ended up about 70K and 1000 lines long, and will still fail in some specific *rare* cases (but it will strip the entire standard distro :-) It would have been quicker to hack to perl source I think. You can have a look to see how over the top it can get here

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

  • Comment on Re: Re: Re: Re: Re: Compressing/Obfuscating a Javascript file

Replies are listed 'Best First'.
Re: Re: Re: Re: Compressing/Obfuscating a Javascript file
by Incognito (Pilgrim) on Oct 10, 2001 at 21:12 UTC
    Thanks for your wisdom, as I do find it honest and straightforward... You write some pretty nice code (I looked at your Perl parser)... and it makes me realize how much I do not know (and how much I've forgotten).

    I agree that it's best to just write a simpler parser, and make some basic rules/assumptions about the code, to satisfy the 99%... I do not feel like hacking into interpreters at this stage of my life.... :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117923]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-16 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found