Just One File with Cappuccino 0.8
cappuccino.org
cappuccino.org
The killer feature here is that "you won’t have to change a single line of code". I love how seamless this is to implement! Oh, and that the images are sent as encoded text - pure awesome.
It wasn't clear from the original article how Cappuccino handles this...do they automatically throw any image that happens to be in a magic directory into the bundle?
There are other details that are different, so I guess I shouldn't have said "exactly". ImageBundle will make a real PNG for you instead of Base64, for example. Although in 2.0 the new generalized ClientBundle facility (same concept, but you can also bundle CSS, XML, a PDF...) promises to use data: URLs, JSON notation, or other representations when its calculated to be size-appropriate.
ImageBundle sounds pretty solid. I guess they are inferring the orientation of an image somehow? I'd like to see how that works. If you use an image in multiple orientations, or if you need to stretch in both directions, using a single .png file just isn't possible, unless there's something I'm missing.
@ImageOptions(flipRtl = true)
...and there's another hint for images that are intended to be tiled: @ImageOptions(repeatStyle=RepeatStyle.Vertical)
There's no scaling yet, but the tiling annotation covers some of the cases where you might want scaling (such as the edges of a corner-rounded/drop-shadowed box of variable size).The CSS names would be obfuscated (and also shortened).
All these features are there to support code-splitting (splitting the one big giant compiled and obfuscated Javascript file with everything into several "chunks" of JS files to be sent on-demand).
I think, in the case of spriting, it would be fair to say that the overhead of loading many images/http requests (and their individual headers) pretty much nullifies the effects of bloating from the encoding.
http://en.wikipedia.org/wiki/Base64
While we're on the subject, Ascii85 is kind of a cool alternative. By increasing the number of characters used for the encoded string and breaking a 32 bit integer apart in an interesting way, it is able to reduce the expansion down to 25%. For every 4 characters in, 5 come out. Again, more info is available on Wikipedia:
http://pastie.textmate.org/695197
My base64 codec turns out to be quite similar to the Cappucino one; oddly, most of the javascript base64 codecs with decent google juice are actually horrible implementations.
The caching tradeoff is there for any spriting technique, it will always be a tradeoff between reducing HTTP requests and increasing caching granularity.
I wonder if you could create a single diff file for minor revisions. Clients would get both files in parallel as most are configured to allow two connections per host.
E.g.:
- index.html with in-line minor diff + data loader.
- data file with resource that is patched before extraction.
The right time to blow away the cache and produce a new monolithic data file would depend on your visitor profile. The nice part is that your changes could touch multiple files and still have the same overhead.
.......quick example over 10 days........
A user visits every day, 1 change per day, 1% of code modified per change:
- file re-consolidated/cached on every change, user downloads 1000%
- with diffs consolidated every 5 days, user downloads 220%
- best case conventional update, user downloads 109% (but probably a lot more)
A typical app has the Cappuccino bundle, and one bundle for the app code, but using an external framework means adding an additional bundle. We're exploring techniques to further concatenate bundles together (we have one in the project, but it has some negative side effects).
The code is all part of Objective-J and the tools, which don't require the framework itself. You could always use those in your project without using Cappuccino.