views:

196

answers:

2

Google has the very nice JavaScript compressor called "Closure"

http://closure-compiler.appspot.com/home

But it's a pain to use for inline JavaScript within an HTML file.

Question: Does an online tool exist where I simply give the input "uncompress.html" and it spits out the compressed version of that HTML with all inline JavaScript compressed as well?

+2  A: 

Minifiers,obfuscators and compressors have been designed to solve the issue of downloading external elements when loading a page. They were never meant to be used for inline JavaScript or CSS since lots of that is normally kept outside of the page in a separate file.

Since you should be gzipping as much as you can, for browsers that can handle gzip, it shouldn't in reality matter that your inline css/javascript isn't minified on the page.

AutomatedTester
You would think but I have A LOT of JavaScript. Simply running Closure alone on my JS is reducing my JavaScript by nearly 94 kb even gzipped. My JavaScript approaching 400 kb (gzipped), so cutting 94 kb of gzipped JS is massive
NickH
if there is that much inline javascript it should probably be in its own file since it would have its own pipe for downloading and doesnt need to go into your all.js file. Modern browsers have 8 pipes for downloading so doubt you would have too much blocking
AutomatedTester
My god 400Kb (compressed) of inline javascript!!!
micmcg
+1  A: 

If you use PHP, you might call the compiler of google in this way, and then use the header to return javascript

<?php
    $script = file_get_contents('http://www.domain.com/scripts/script.js');
    $ch = curl_init('http://closure-compiler.appspot.com/compile');

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code=' . urlencode($script));
    $output = curl_exec($ch);
    curl_close($ch);

    header('Content-type: application/javascript');
    echo $output;

?>

link php code

andres descalzo