Tuesday, December 14, 2010

Web: Better URL navigation

This post made me realize that very few people are aware of a nice way to work with URLs for dynamic content.

Many sites use the hash (#) or shebang (#!) in their URLs for AJAX, and some end up breaking the *Back* button on your browser. The hash is important for letting Google index a link to a self-reloading page, but for pages that should not be indexed, there is a better way.
  •    http://foo.com/current.html
    • Contains a POST-method link to "/link".
  •    http://foo.com/link
    • On the server, the web framework interprets POST, computes new context, then redirects to the template "final.html", along with extra context.
  •    http://foo.com/final.html
    • This would be the result of the template substitution.
There are several benefits to this scheme:
  1. POST interpretation (the "controller") is separated from template substitution (the "view"). Most people instead use an if-clause in their controller.
  2. The web-designer can keep a simple redirect stub for the "link" page. That way, he can continue web-design in his static environment. He does not have to use a server or the intended framework.
  3. final.html is inherently secure, since none of the extra context is ever provided directly to that URL by the user.
The *Back* button works fine, because the `link` page was never rendered.

I'm not sure why this pattern is not better known. Maybe I am overlooking some advantages of the alternatives.

No comments:

Post a Comment