Closure + gzip -9 and Memcache
To squeeze the fast juice from our networks we did the following:
- Run Google Closure Advanced (requires code fixes)
- Gzip with max compression (gzip -9)
- Memcache this file (or APC if using PHP)
- If a CDN is in your budget, use this instead.
- If using Google App Engine, you get both Memcache+CDN!
Also modify headers to a set of FOUR. Make sure there are no more than FOUR because headers are uncompressed.
- ‘Content-Length’ = 1234
- ‘Conent-Encoding’ = ‘gzip’
- ‘Expires’ = ‘Wed, 01 Jan 2025 16:00:00 GMT’
Also consider adding Proxy Cache-Control header for extra chances of cached data on a local box for people who live in remote regions.
To test the amount of juice that can be sqeezed, run the following command:
This command will report a total byte count which tells the payload size. Under 4,000 bytes is the goal. Our PUBNUB Library is under 2,900 bytes.
You’ll want to grab Closure Compiler if you don’t yet have it. Download Google Closure Compiler.
Google Closure Compiler Advanced
To start, running Google Closure in Advanced Mode requires you to specify which object descendants must not be reduced to a single letter (‘object.apple’ to ‘o.a’).
These are important to identify especially if JSON + AJAX is invovled. JSON accessed by the compiled code is not referencable.
The Solution is to wrap the descendants name with [‘some_val’]
Otherwise this will happen:
Now you can safely execute Google Closure Compiler with Advanced Optimizations.
Google App Engine CDN
send-optimized.sh has every server IP and access key for ssh access. Or in the case of GAE, a secure custom delivery API.
CDN Other than Google
If you are using another CDN, you’ll need to forget about the memcache step listed above. However choosing a CDN over Memcache is much better especially if your audience is international. Your send-optimized.sh script will instead deliver the gzipped file to your CDN gateway.
Fast is Important
Page delivery speed is crucial and has direct correlation with revenue. In the case of Google, adding only 100ms to each page request drops revenue several percent. That will be a large number for Google.
Take into account all the mobile users and growing network congestions. Slow network speeds can be improved by following Closure + Gzip + Memcache + CDN + Header changes.
Don’t forget international! With all these Optimizations, your friends in other countries can enjoy a speedy web experience too.