I am looking for a way to compress JavaScript code for iPhone. Is there a way to avoid using a lot of processor time on a small and rather slow device?
Use JSMin and avoid packer , which actually consumes more processor and slows down "pumping"
Use YUI Compressor
I love ShrinkSafe . It interprets your code in Rhino, then returns the compressed code. Since it works with real interpretable code (instead of complex string evaluations), it will never encode code or be able to distinguish between public and private variables.
This is an excellent quality tool.
We used js_compactor and JavaScriptLint to βcompileβ and compress our JavaScript in our automated build process. A further build step will compress JavaScript and merge related files into one package. The performance increase was significant, but keep in mind that you cannot trade with debugging capabilities.
Reducing the number of files transferred to the client will give you a big performance boost if you have multiple files. As a rule, browsers open only 2 connections to one server at a time, therefore, even if you transfer compressed and minimized files, the browser spends a significant amount of overhead on its cache. yslow helped us determine why pages took a long time to load and help us focus our optimization efforts. We used our environment to use unprocessed files or minimized and compressed versions .
I believe that Safari on iPhone supports gzip output, so you can use something like mod_deflate. I had better results using this method. There is not enough material to compress JavaScript, there is absolute garbage and takes longer to unpack than to load a larger file. JSMin looks pretty good.
You can try various tools in JavaScript CompressorRater . All tools except the packer do not affect javascript execution speed, as far as I know - they remove only spaces, rename variables, etc.
I myself consider YUI Compressor the best.
It is always useful to check the code in JSLint first to make sure that the compressor understands it correctly.
Make sure your web server is serving gzipped / deblated files correctly, when the client supports it, it is usually more efficient than minimizing the program code itself. Of course, using both tends to be even smaller.
I missed this little dance in the last few days. We tried using Packer , but found that our packaged JavaScript took more than 2 seconds to execute (not to mention blocking other downloads). Based on this article, we switched to YUI Compressor . Not only are gzipped files smaller, the runtime is less than 300 ms.