views:

45

answers:

1

I am in the process of creating an HTML application, in the sense that there will only be one HTML page and the rest will be done as AJAX using jQuery.

I will be storing context in the hash of the URL to preserve the back button and allow external deep-linking from our main site. I will use onhashchange to detect a request for new content. With that, I would use a link such as <a href="#product/sku-1">Link</a> to cause the application to go GET /api/product/sku-1.js as JSON, after which I would need a dispatch strategy to route that JSON to the proper renderer.

My initial thought was a set of regexes in onhashchange to set the callback of the ajax call based on the requested resource, but that makes a large assumption that rendering is always the same for any given resource. I don't have any current requirements that this assumption breaks, but I hate to tie my hands this early in the game.

Have any of you any advice to offer on patterns that work for this problem? I can think of at least 3 ways to handle this right now, but I'd like some insight from anyone who has had a prior experience with this before I make a command decision and move out.

A: 

Just to clarify - are you planning to use a js page as the AJAX server? Why not use a webservice model? That way you can just have one webservice URL and call whatever functions as necessary with parameters derived from the # bookmark.

jambox
That doesn't solve the problem of dispatching to the proper renderer. Basically I needed a mapping that said, "when this hash pattern is clicked, go get this remote resource and then route the response to this renderer."
Joel Clark
Ah render as in transform into html? I've never tried that before, instead i've always deserialised it and put the resulting values into the DOM one way or another. I have to maintain XSLT transforms of XML at work and I don't love that approach, but perhaps that's substantially different.
jambox
btw i'm probably in over my head here but i was intrigued by the question.
jambox
Correct, if I am going to go download a list of products, it has to be rendered into markup somewhere. The plan is to write the application entirely in html5 and js.
Joel Clark