There are a number of popular web applications that are built in the context of a single page and that rely heavily on Ajax and RESTful events to provide the functionality that drives their behavior. Google Reader and Gmail are good examples.
I think most of us would agree that the fewer the page loads, the better. There’s something inherently nice about quick, responsive applications that run in the browser. Of course, it can be somewhat of a challenge to implement such functionality.
Sammy.js attempts to change that.
Built on top of jQuery, Sammy, is a JavaScript framework that is based on RESTful events. It can be used to develop single-page, Ajax-enabled applications.
If you’re familiar with the model-view-controller design pattern (or any of the web frameworks based off of said pattern), then picking up Sammy should feel familiar. It uses the concept of routes to make requests and drive content throughout your page.
For example, assuming that you have an anchor that has an href of, say, “exampleData,” you can capture the event to drive content by:
[cc lang=”javascript”]
var SammyApp = $.sammy(function() {
this.get(‘#/exampleData’, function() {
$(‘#content’).text(‘Driving content from another link!’);
});
});
[/cc]
Of course, there’s much, much more to Sammy. To get started, checkout the website, its documentation, and the GitHub repository.
Speak your mind...