Proxying script requests through Google Closure Compiler
Since Google's Closure Compiler also comes in a public web API flavor (and one that doesn't require a key!) I set about writing some code to proxy all incoming javascript requests through it.
I used an ASP.Net MVC implementation where calls to the route (e.g. "/script/myscript.js") would look for the uncompressed javascript file, and if it exists it will dispatch the Closure Compiler and return that result.
I cache the results in ASP.Net's global cache so I can look there first, and if my web farm uses a distributed/shared cache, they all benefit. Additionally, I added a file Cache Dependency so that if the script file ever gets updated, the minified version will be automatically evicted from the cache and regenerated when accessed next.
Next I added a routine in Global.asax.cs Application_Start method to iterate through all Javascript files in my website and send them through the Closure Compiler meat grinder so they are all preloaded into the cache. Since this can be quite time consuming, spinning it off into it's own thread keeps the web site from starting too slowly.
The end result is that whenever my website is started or recycled, it will grab all the JavaScript files, send them out to Google Closure Compiler's public API, and then cache the results. Whenever a script file is modified it will evict the minified version from the cache and be regenerated the next time the script is requested.
