Javascript has a place in web development. Unfortunately, many have assumed that the script has such extensive support that it can be used for all dynamic web development. This is simply a hack and should be condemned as such. It ruins security since everything is rendered via the client-side. And it alienates users that are not fond of javascript (I am only referring to client-side javascript, not server-side libraries, such as Node.js).
Server-side page rendering should be performed to initially render the page and AJAX deployed only for page changes. All links must create a page refresh if the user doesn't support javascript and the page be rendered server-side. This is good, backwards-compatible web-developing. The server should always be a fall-back resource, not simply a hard drive to serve up the files.
There is one specific method of providing an "optimal" user experience that violates all of these protocols. This is the hash-bang part of the URL. The hash-bang part is the part after the hash-exclamation-point. Hash-fragments have been around for a while. The hash fragment is in green. www.example.com/users#arithehun. This has typically been used to refer to the name attribute of an anchor (this would push the page down to the HTML semantic: <a name="arithehun"></a>. However, since AJAX has come about (asynchronous javascript and xml), a programming language greatly supported by jQuery that retrieves server-side requests in through javascript and retrieves them in HTTP GET and POST requests through XML coding, this hash-fragment has assumed a more sinister role. It is often used as a key-value system to change variables in AJAX, triggering asynchronous server-side requests. Exclamation points are illegal in HTML, so this is often done in hash-bangs instead of just a hash to make sure it does not refer to an anchor. Now it would be just www.example.com/users/!#/arithehun.
"So", you may ask (innocently), "what is the problem with this nifty HTTP-GET-like interface? Doesn't it allow websites to merge javascript and the address bar?" The answer is that it promotes hacking, not software engineering, a quandary I hope does not take the next generation of programmers. Let me elaborate. We all know about the passing in GET/Request values in a web page. example.com/users.aspx?name=arithehun. Now that the MVC architectural pattern has emerged, we are (thank G-d) beginning to see more implementation of REST (representational state transfer), particularly in ASP.NET and Ruby on Rails. This allows more of an arbitrary URI paradise which allows us to build URIs conceptually instead of being bound to URLs. People can define custom routes too, so for a user query, "User/{name}". Instead this URL becomes example.com/Users/arithehun. This will probably call a method which selects the name of all users for username arithehun (or the .Single(n => n.username == "arithehun") connotation). This is all great and well, signaling the great strides that could be lost due to hash-bang fragments.
The problem with hash-bang fragments is that they use the !, so they cannot be rendered by HTML, and the # excludes them from using the HTTP protocol. This means that to function, they must be decoded by AJAX and AJAX alone. This may make web developers build the functionality of their applications into the AJAX states. All the nice RESTfullness is lost and so is all DRYness.
Now you may now dismiss me as an HTML4 crony dismissing a new, fun, and interactive web. However, precisely the opposite is true. My alternative is in fact an HTML5 answer to hash-fragments. It uses the history.pushState. Basically, you simply, when the button is pressed, issue a listener that interrupts the HTTP request and performs a javascript function instead that basically queries a similar function that returns a partial view which can be retrieved via a XML and inserted into the page. Then push the would-be URI into the address bar. If someone refreshes the page, the inherent URI is simply processed via server-side and rendered like the pre-javascript days. Back-requests can even be handled with a listener. And what if the user doesn't have javascript? Then the links are just links just like the good old days. If you are feeling really cocky and don't want a user with javascript to ever re-render the page when the URI is changed (like a hash fragment), then simply add a listener for a URI change and perform the same request:
window.addEventListener("popstate", function(e) { // do something }); .
It's quick, easy, and automatically backwards-compatible.
This HTML5 solution may not be as simple and intuitive as the hash-fragment, but is loosely-coupling your classes and patterns more simple than not? The answer is "no", but they make your site much more modifiable, stable, and legacy-supported.
To get started with this HTML5 history.pushState solution, follow this simple getting-started tutorial: http://diveintohtml5.info/history.html
Read more awesomeness from Ari Falkner >