Web Applications – What State Information Should the URL Contain in a JavaScript Only Web Application?

web-applicationsweb-design

I'm writing a single page web application that talks to a business layer via asynchronous RPC (encoded with json). I'm targeting fairly modern browsers, so I can at minimum control the URL after the hash. However, the URL won't really be what drives the application's state (that will be maintained by a javascript model layer), so I don't have to do anything with it. I could even keep it the same the whole time without any implementation problem.

The question is, what should go in the URL? I won't go into the application because I'm hoping the question is generally useful. What kinds of expectations do users have about backward and forward buttons? About typing in a URL? Are there currently any generally applicable best practices yet for this kind of application?

Best Answer

The URL should be used for what it does: locating a resource.

You should put in the URL only things relative to the location of the resource, so users will be able to always find it (bookmark, permalink). With this in mind, you should avoid to insert variables in it or other custom data.

Just look at the link of this question for example, and how easy it is to share between social networks.

You should also consider that many users (like me) may prefer to navigate your site directly from the URL bar. For example playing with numbers. If I'm reading a blog article with a URL containing a folder named 2011, I could try to remove all the URL part up to the year folder, expecting to see a page which contains all the 2011 articles.

Then I could also change 2011 to 2010 to browser last year articles, and so on...

Too often websites provides very basic (and sometimes inefficient or completely absent) navigation commands. It's often easier to navigate a website directly via the URL bar.

Edit

I would also like to add that the URL should describe as much as possible what is the content of the linked resource, using clear keywords, not random numbers or misleading/useless words.

Related Topic