A pattern for your consideration, about using Ajax to help pages be RESTful.

Problem

How to personalize content and make pages cacheable and bookmarkable at the same time?

Forces

  • We want pages to have clean URLs that describe the main content being viewed. Doing so makes pages easily bookmarkable and send-to-friend-able, and also allows us to cache the page anywhere along the way. For example, viewing info about Fight Club should be http://example.com/fightclub and not http://example.com/fightclub/user-mahemoff or http://example.com/fightclub/287490270-1931321-cijE12ZSz</li>.
  • We want to personalize pages - say Hi to the user, show them personalized recommendations, etc.
  • If we personalize, but use the same URL for all users, we break REST and therefore won't be able to cache any content. My http://example.com/fightclub is different to your http://example.com/fightclub because we each see our own recommendations inside the page.
  • But if we use diferent URLs for personalization, we can't cache across users and pages aren't sent-to-friend-able. If I look up and see http://example.com/fightclub/user-mahemoff, I'm probably not going to bother sending you the URL. Furthermore, my view of the page can't be cached. </ul>

    Solution

    Create pages generically (same version for all users), and in this generic version, embed a remoting call which will customize the page for the current user. Serve http://example.com/fightclub to everyone. Then everyone's browser makes a further call to grab custom content (Multi-Stage Download). This additional call is unRESTful as the server will use cookies to decide what content to return, but at least we've isolated that component, served the bulk of the content without caching, and given the user something they can bookmark and send to their friends.

    References