473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Any Javascript Obfuscator?

hsriat
1,654 Expert 1GB
Is there any free Javascript Obsfucator available?

Actually I just want the obsfucator to do two things...
1. Remove Comments
2. Rename Functions and Variables
Feb 17 '08 #1
15 4196
acoder
16,027 Expert Mod 8TB
You may find JSMin useful (at least for the first objective).
Feb 18 '08 #2
hsriat
1,654 Expert 1GB
You may find JSMin useful (at least for the first objective).
I downloaded the PHP code and made a php file to upload the required js file.
Like this:
[PHP]<?php
//file name: minify.php
if (!isset($_POST['Submit']))
{
?>
<html>
<form action=minify.php method=post enctype="multipart/form-data">
<input type=file name=js></input>
<input type=submit name=Submit value=Minify>
</form>
</html>
<?php
}
else
{
include('jsmin-1.1.0.php');

if ($_FILES['js']['error']>0)
die ('Error Uploading File');

$file_js = fopen($_FILES['js']['tmp_name'],"r");
$js = fread($file_js,$_FILES['js']['size']);
//echo $js;

$min = new JSMin;

$minified = $min->minify($js);

//echo $minified;
}
?>[/PHP]
But it gives this warning...

Missing argument 1 for JSMin::__construct()

What to do...

PS: I don't understand OOP Concepts :(
Feb 18 '08 #3
acoder
16,027 Expert Mod 8TB
I suggest you ask in the PHP forum.
Feb 18 '08 #4
hsriat
1,654 Expert 1GB
I suggest you ask in the PHP forum.
Yeah, you are right!!
My fault!!
Feb 18 '08 #5
rnd me
427 Expert 256MB
I use firefox to compress it.

wrap your code in a function, then compress by using the .toSource() method on the function.


Example:
Expand|Select|Wrap|Line Numbers
  1. function BS(){
  2.  
  3.  
  4. function el2(tid) {
  5.     return document.getElementById(tid);
  6. }
  7.  
  8. function tags(elm, tid) {
  9.     if (tid) {
  10.         if (elm.isString) {
  11.             elm = el(elm);
  12.         }
  13.         return obValsl(elm.getElementsByTagName(tid));
  14.     }
  15.     return obValsl(document.getElementsByTagName(elm));
  16. }
  17.  
  18. }
  19.  
  20.  
  21. alert(BS.toSource())
  22. /* returns:
  23. function BS() {
  24. function el2(tid) {return document.getElementById(tid);}
  25.  
  26. function tags(elm, tid) {if (tid) {if (elm.isString) {elm = el(elm);}return obValsl(elm.getElementsByTagName(tid));}return obValsl(document.getElementsByTagName(elm));}
  27. }   */
  28.  

remember to remove the first and last line of the resulting text, the function wrapper.
Feb 18 '08 #6
acoder
16,027 Expert Mod 8TB
I use firefox to compress it.

wrap your code in a function, then compress by using the .toSource() method on the function.
Nice tip (for compression, at least)!
Feb 18 '08 #7
acoder
16,027 Expert Mod 8TB
Is there any free Javascript Obsfucator available?

Actually I just want the obsfucator to do two things...
1. Remove Comments
2. Rename Functions and Variables
By the way, is this just to cut down on the size of the script? This is what minification is for.
Feb 18 '08 #8
hsriat
1,654 Expert 1GB
@acoder
Yeah, coz I ended up making at least 10 js files of all approx 25 kb. So I wanted to cut down the size. And I know the actual code size (w/o comments and spaces) is approx 15 kb, may be less than that.

@rnd me
Cool!! Thanks... :)
Feb 18 '08 #9
acoder
16,027 Expert Mod 8TB
@acoder
Yeah, coz I ended up making at least 10 js files of all approx 25 kb. So I wanted to cut down the size. And I know the actual code size (w/o comments and spaces) is approx 15 kb, may be less than that.
So, did you manage to cut it down in size?
Feb 19 '08 #10
hsriat
1,654 Expert 1GB
So, did you manage to cut it down in size?
I didn't do it yet...
Will do after testing.

Will tell you how much file size reduces...
Feb 19 '08 #11
rnd me
427 Expert 256MB
remember that in javascript, variable names are case-sensitive, so performing global replaces on compressed code could be an easy way to obfuscate names.

if you have a funciton or prototype for doing mulitple replaces, you could feed it a an array of function names, and have it substitute a serial number for each.



continuing above,
Expand|Select|Wrap|Line Numbers
  1.  
  2. String.prototype.substitute = function (r) {
  3.     O = this;
  4.     for (z = 0; z < r.length; z++) {
  5.         tre = new RegExp(r[z][0], "gm");
  6.         O = O.replace(tre, r[z][1]);
  7.     }
  8.     return O;
  9. }
  10.  
  11.  
  12. function serial(dig) {
  13.     var bb = "";
  14.   if(!dig){ dig=5; } 
  15.     for (var q = 0; q < dig; q = q + 1) {
  16.         bb = bb + String.fromCharCode(Math.round(Math.random() * 25 + 65));
  17.     }
  18.     return bb;
  19. }
  20.  
  21. var subs=[
  22.   ["el2",serial()],
  23.   [ "tags", serial()]
  24.    ] //end sub array
  25. alert(BS.toSource().substitute(subs) )
  26.  
  27.  
Feb 19 '08 #12
hsriat
1,654 Expert 1GB
So, did you manage to cut it down in size?
Yeah, quite a lot.

A 32kb well commented JS was reduced to 19 kb.
And a 15 kb, non-commented JS reduced to 14 kb (not too much tho :p)
Feb 25 '08 #13
acoder
16,027 Expert Mod 8TB
Yeah, quite a lot.

A 32kb well commented JS was reduced to 19 kb.
And a 15 kb, non-commented JS reduced to 14 kb (not too much tho :p)
Every little helps, eh?

If you're using long names for variables, functions, etc. you may want to replace those too.
Feb 25 '08 #14
hsriat
1,654 Expert 1GB
Every little helps, eh?

If you're using long names for variables, functions, etc. you may want to replace those too.
Yeah, I wanted to, but the thing you referred to didn't do that :p

And I don't want to do the find replace thing. B'coz with that, when I would do any change, after doing that with the original (commented) file, I would need to do the whole find-replace thing again.

So I wanted a one-click-solution, so that after making any change, I can get the minified* version quickly and upload it to server again.

* term used by that guy who made that program.
Feb 25 '08 #15
acoder
16,027 Expert Mod 8TB
Yeah, I wanted to, but the thing you referred to didn't do that :p

And I don't want to do the find replace thing. B'coz with that, when I would do any change, after doing that with the original (commented) file, I would need to do the whole find-replace thing again.

So I wanted a one-click-solution, so that after making any change, I can get the minified* version quickly and upload it to server again.

* term used by that guy who made that program.
Try YUI Compressor, Packer or ShrinkSafe (Dojo).
Feb 25 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Smugsboy | last post by:
Anyone. Where can I find a free javascript scrambler/obfuscator, that can be ran from command-line. Is there one that can be used as a frontpage plugin ? Thanks,
2
by: Luke Matuszewski | last post by:
Hi, Can anyone point me for some JavaScript Obfuscators ? I know one written by Dean Edwards (but it do not substitute variable names, which a would like to do). B.R. Luke Matuszewski
20
by: korund | last post by:
I want encrypt javascript code in web page, however, browser need fully recognize it.. There any many Javascript Obfuscators in the Net. Is there some good and handy utility(or script) among them...
30
by: mistral | last post by:
Neeed good javascript unescape encoder, to protect javascript code. Some advices? Online tool, or ready javascript only. Any opinions about the Javascript Obfuscator:...
20
by: twigster | last post by:
Hey everyone, I'm looking for a good way to obfuscate some Javascript code. Does anyone have a good experience or bad experience with a particular software? thanks
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I protect my javascript code? ----------------------------------------------------------------------- ...
2
by: Laurent Bugnion [MVP] | last post by:
Hi group, A few years ago, I translated Douglas Crockford's JsMin from C to C#, because we wanted to use this functionality in our build process. JsMin is a code minimizer for JavaScript. It...
4
by: Peter Michaux | last post by:
Hi, I've uploaded a new version of the JavaScript::Minifier module that was on CPAN. It was a translation of JSMin but I rewrote it so it now handles missing semicolons, + ++ code, and leaves...
11
by: =?iso-8859-1?q?Martin_M=FCcke?= | last post by:
Hi, I am looking for a good javascript obfuscator - I found several on the web, but I am looking for one that can also handle javascript in jsp, html and java files - so I need a javascript...
3
by: crymari2 | last post by:
Hello, I have a need to make my javascript really difficult to study. A lot of people think that this is useless waste of resources, but they are wrong IMHO. I need your recommendation of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.