Posted By

insane on 04/09/11


Tagged

html google closure compress static ofuscate


Versions (?)

Compress and Ofuscate static html pages using php and google closure


 / Published in: PHP
 

It compress an static html page using php and output the response using document.write giving us a nice and ofuscated output check out your page source code after view it ;)

  1. <?php
  2. $signature = 'My signature';
  3.  
  4. $content = file_get_contents('index.html'); //or whatever you want
  5.  
  6. $content = preg_replace('/>[\t\n\s]+</m', '><', $content); //remove spaces
  7.  
  8. //make javascript handle our output
  9.  
  10. $script = sprintf('(function(e){var w="",s="",d = document; while((s=e.pop())!=undefined) w+=s; d["write"](w); })(%s);'
  11. ,json_encode(
  12. array_pad(array(), 50, '/*d[n_n]b*/')
  13. ,split("<[.*^>]",$content)
  14. )));
  15.  
  16. $ch = curl_init('http://closure-compiler.appspot.com/compile');
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  18. curl_setopt($ch, CURLOPT_POST, 1);
  19. curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=ADVANCED_OPTIMIZATIONS&js_code=' . urlencode($script));
  20. $g_output = curl_exec($ch);
  21. curl_close($ch);
  22.  
  23. $jsContent = sprintf('<script>'."\n\n/*%s*/\n%s\n".'</script>',$signature,$g_output);
  24.  
  25. echo $jsContent;
  26. ?>

Report this snippet  

You need to login to post a comment.