2

My project consists of javascripts of two different types:

  1. External regular .js files.
  2. <script> code embedded into PHP code, some parts of javascript are generated from PHP, like:

var a = <?php echo Res::a; ?>;

Now I want to obfuscate/minify the whole project: both external and embedded javascripts and PHP itself. Unfortunately, all tools I've seen work with single .js files.

noober
  • 4,819
  • 12
  • 49
  • 85
  • 3
    Obfocusing/minifying PHP is meaningless. If your project is open to the public, why minify it? If it's not... why minify it? – Madara's Ghost Jul 20 '12 at 12:55
  • [Check out this link](http://stackoverflow.com/questions/232736/code-obfuscator-for-php) too see why obfuscation is pointless in any language. – George Reith Jul 20 '12 at 13:35
  • @noober To clarify, I flagged the below post about product placement on the site. I also have no affiliation to the good people at Stack Overflow except I value the contribution to the web development community they have created. I believe this question has potential merit if it's re-worded to something like: "how do I use google closure compiler for inline JS" – Jasper Feb 20 '13 at 19:42
  • @GeorgeReith For security, yes minification is basically pointless, however you can affect network and cpu performance via obfuscating/minifing. You can also streamline your development process by using inline comments as documentation and then removing those comments automatically via minification. – Jasper Feb 20 '13 at 19:45
  • @Jasper Indeed but I was referring to obfuscation not minification. They aren't the same thing. – George Reith Feb 20 '13 at 21:11
  • @GeorgeReith No they aren't the same, but `obfuscation` still decreases the overall size of the file by shortening variable names. – Jasper Feb 20 '13 at 21:49
  • 1
    @Noober: you were right, this got closed by SO's apparant policy that seems to be focused on killing dicussions about tools. I think this is a huge loss of utility by SO for programmers, who live and die by the tools they use. – Ira Baxter Feb 21 '13 at 11:33

2 Answers2

2

I think this issue if too specific to be answered with a single all-purpose tool.

A method to to it could be to use placeholder in your Javascript to replace PHP code.

var a = PHP_SOURCE_1;

Minify your javascript, using a js minifier such as Yui Compressor http://developer.yahoo.com/yui/compressor/ Then replace the placeholders by the original PHP source.

Ideally in order to properly minify your javascript code, you'll need to externalize your embedded scripts.

Tchoupi
  • 14,560
  • 5
  • 37
  • 71
1

Now I want to obfuscate/minify the whole project: both external and embedded javascripts and PHP itself. Unfortunately, all tools I've seen work with single .js files.

Try VarHammer JS obfuscator

igorGIS
  • 1,888
  • 4
  • 27
  • 41