Boiler: An experiment in client-side everything.
What the hell?
Boiler is a jQuery plugin that takes URLs to a mustache.js template and a data file (JSON or CSV) mashes them up and inserts their content into the page. Optionally, it will repeat the process of loading the data and regenerating the mashup and a configurable interval.
For near-real-time updates without complicated push/comet infrastructure. Clients can poll for a small datafile hosted on very cheap infrastructure (S3, etc.) and render it using a template that was fetched on load. The data file can be updated by a server process with no knowledge of its users and the client can repeat its fetch-and-render cycle very frequently.
The code as written is currently targeted at embeddable widgets, but the principle would be straightforward to apply to full-pages.
You will need a way to serve the files. I suggest executing the following Python one-liner:
% python -m SimpleHTTPServer
Because this plugin supports cross-site hosting of the template and data files, your files will need to be wrapped in a JSONP callback. Boiler includes a script that will automatically do this for files put into the ‘data’ and ‘templates’ directories. You must run this before running the example:
% python jsonpify.py
Boiler + Stovetop
Boiler can be combined with Stovetop to
fetch data from Google Spreadsheets.
Is it tested?
Not at all. Only in the latest non-dev Chrome and only on OSX.
- Hashing may be used to avoid re-rendering identical content.
- Its entirely unclear how fast this is or how frequent polling could be on “average” computers.
- In the future boiler will take a param specifying how often to poll for new content and automatically show/hide a loading icon (“throbber”) in the rendered template (likely using a magic div id).
- User needs to handle “no-cache” headers on the data file or the browser will cache the result of the AJAX call.
- It would make sense for the JSONP requirement to be conditional depending on whether or no the AJAX requests are cross-site.
All code by Christopher Groskopf—courtesy of a Saturday evening, good whiskey, and Chevelle.