views:

243

answers:

2

I have previously written my web apps with a server side / html template language type design. I am interested in writing a static html client that uses javascript to fetch data from a restful service (ala couchdb). It dawned on me that I could not in one web request get both the static html file, and the json data that is used to populate it. This is not a problem by itself, but if I have a requirement for bookmarkable urls, how can I make this work?

/users/ -> downloads users.html -> ajax request looks up users.

/users/bob -> downloads user.html -> ajax request looks up bob.

Is this a reasonable design? It gives me a lot of flexibility on the backend, as well as making it easy to collaborate with a designer. Anyone done something similar, or have an alternate suggestion?

Thanks!

+1  A: 

That's fine except you are causing 2 requests for each page. Can you streamline it like this:

<script type="text/javascript">
    var INITIAL_DATA = {json: 'data', here: 'from', server: 'side'}

    onDocumentReady()
    {
        PopulateScreen(INITIAL_DATA);
    }

</script>

Then you can use Ajax to refresh the screen with a different data set with a single request, later in the life of the page.

Eliminates the duplicate request issue.

gahooa
A: 

Any luck on this? I've been working on this, first with Cloudkit/Tokyo Cabinet and now with CouchDB. I'm getting issues with "cross scripting" errors, where the client thinks its on a different domain, I'm guessing because the port number on CouchDB, etc. is different.

alxross
I am currently calling back to the same port, so I am not seeing your issue. I chose riak, which has an http client (jiak) that I could use in the same way you are with couchdb. I assume I will run in to the same problem you are. If/when I do that I will let you know if I find a solution, and if you find one before that please let me know!
Chris Duesing