Spine.js, Zepto and the holy Ajax
There are many client-side MV* frameworks out there. My framework de jour is Spine.js, which I have grown to like and appreciate.
However, like most frameworks out there, Spine depends on jQuery (or Zepto to an extend) to properly work. Although understandable (jQuery is a pretty common library these days), this dependency is in my opinion pretty short-sighted and annoying, especially when it comes to writing mobile-first Web apps.
Spine does say that they’re compatible with Zepto, which is a more reasonable choice for mobile-first apps, due to its smaller size, but alas, Spine.Ajax, which depends on jQuery deferred and queue, will not work with Zepto.
So, in simple words, the Spine.js people say - If you want to use Zepto, you can, as long as your app is offline and doesn’t need Ajax.
Although I have the utmost respect for the maintainers of the Spine.js project, this has been driving me crazy these past few weeks, as I cannot, for the life of me, understand why my users should be punished with 50+KB of jQuery download if they access my app via mobile.
So, if you’re like me, and use Spine.js with Zepto, and want to get your Spine.Ajax to play nice, here’s what you need to do:
- Add zepto-deferred to your source code and install into Zepto (see instructions on the Github page)
- Add the following Gist to your source code (note that this doesn’t provide full-fledged queues to Zepto. It only adds enough support for Spine.Ajax to queue requests properly
[javascript src=”https://gist.github.com/zohararad/5648378.js“]
Happy coding
Comments