2009 May 04
Yes, the name Binks is just so I could make that pun.
A BIG shoutout to the nochump blog where I got the excellent zip parsing utility. That link is currently down, but google has a cache. Here's the nochump library in case you can't get to the official site: nochump-ziplib-105-src.zip. It should be fine to redistribute this since it was MIT licensed.
Like jar files, and jawr, Binks is a way of bundling resources to deliver them in a compressed fashion. The advantages to this are:- by bundling, a single http connection is used for many resources
- zip compression is at least as good as (and often better than) other js minification schemes.
- I personally find the ability to zip up and deploy a whole crapload of stuff at once quite appealing
- It runs after the page loads, so things like jQuery's document.ready are less usable.
- Since it injects css as if it was written in a style tag on the page, relative urls for things like background images will break
- If you're not already including flash and swfobject, that's two extra dependencies. Technically swfobject isn't needed, but it's definitely easier
To use Binks, you just need to include it as any other swf file, with a flashvar named src which has the url of the zip file to load. Since there's really nothing to see or interact with, you can even put the swf in an invisible div. I have not done that here, but it's possible. See the source of this page for an example of how to set the flashvar.
Binks will search through the zip file for any css and js files. It then inserts the css files first, then the js files. If you prefer to control exactly which files are inserted and in what order, you can create a manifest.xml file in your zip file. If a manifest is detected, only those files listed in the manifest will be loaded, in the order they are listed. The manifest is a very simple xml file consisting of a root node "manifest" and then one or more "entry" nodes whose contents are just the file names in the zip archive. See the binksFiles.zip listed later for an example.
Since Binks ignores files that are not listed in the manifest (and without a manifest it ignores anything that isn't css or js), you can put other resources in the same archive. For instance, I've put the Binks source and example files in binksFiles.zip along with the css and js it loads dynamically.
