3

I've been looking around SO for a JavaScript obfuscation script of some kind, note that I'm not looking for a compressor, I need an obfuscation script/code that will shrink the JavaScript files I have in PHP (not in JavaScript) for production reasons.

I've heard about Minify, I've used it a couple times, works great but it doesn't obfuscate my JS code, simply that is all I need to have, think like the Dean Edwards packer but without packing it, just the shrink variables mode in PHP instead of JS.

EDIT: My mistake, I understood "obfuscate" wrongly, I mean minification on the JS code - shrinking variable names and removing whitespace, etc. Minify is the closest I got to, but it does not shrink variables.

Is there one out there?

5
  • Just FYI: Obfuscating code usually makes it larger. Shrinking variable names is part of minifying code, not obfuscating it. Commented Nov 18, 2011 at 20:32
  • 1
    Try google, gives you tons of obfuscators "out there". Commented Nov 18, 2011 at 20:33
  • I agree, this is question for google, not SA... Commented Nov 18, 2011 at 20:51
  • @Rocket My bad, read my edit. Commented Nov 18, 2011 at 22:27
  • Do you have the option of utilizing the Closure Compiler JAR through PHP? Commented Nov 18, 2011 at 22:31

4 Answers 4

2
exec('java.exe -jar compiler.jar --js pre.js --manage_closure_dependencies true --js_output_file end.js');

exec('java.exe -jar yuicompressor.jar pre.js  -o end.js');

use:

google closure compiler AND http://developer.yahoo.com/yui/compressor/

Sign up to request clarification or add additional context in comments.

Comments

1

Our ECMAScript Obfuscator probably does what you want. In particular, it will find JavaScript chunks in PHP files and obfuscate/minify depending on what you want.

2 Comments

You recommended a paid version. Perhaps it would be nice if there was a free script apart from your obfuscator.
You asked if there was one out there. There are others that work on plain Javascript. There are others that work with HTML but I have no idea if they work with PHP scripts, which is what you asked for.
0

I'm pretty sure this is what you're looking for. And I dont' know if you'll be able to find a solution that does it better than Google: http://code.google.com/speed/articles/compressing-javascript.html

Comments

0

I know this is an old question -- but it needs an updated answer, as there are now PHP implementations of jsMin

eg: http://wonko.com/post/a_faster_jsmin_library_for_php

Note: When you say "shrink variables" it's important to clarify: Most minifiers will only shrink local variables within functions, but leave globals and function names -- as renaming those would likely break interoperability with the page / DOM elements / other scripts, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.