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.