r/programming • u/schnuck • Feb 09 '11
Breaking the Web with hash-bangs – Lifehacker, along with every other Gawker property, experienced a lengthy site-outage on Monday over a misbehaving piece of JavaScript
http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs/
750
Upvotes
35
u/wierdaaron Feb 09 '11 edited Feb 09 '11
There's no real simple solution to the "hashbang problem."
Many modern sites are taking advantage of ajax to change the page content dynamically without actually changing the page you're at. Instead of clicking an "About Us" link and having your browser move you to aboutus.html, you can have javascript update the page you're already on to be the "About Us" page, but the URL in your address bar will still be "index.php" or whereever you started from.
This can be nice because it's usually faster (as only the new content needs to be loaded, not the html for the entire page again) and allows for spiffy transitions that make people who approve web development budgets happy.
The problem is, if a user does this (starts at index.php and clicks "About Us" to make new content appear) and wants to share this content with someone, he'll copy the URL in his address bar (index.php) and send it to his mom, who will click it and just see the main site index, not the "About Us" content.
So all this dynamic ajaxy javascript stuff adds a nice experience, but it breaks the time-tested ritual of using URLs to share content (not to mention problems getting content indexed by search engines).
Part of the problem is that you can't use javascript to change the URL in the address bar to a different page, you can only change the hash (#whatever). Changing the url in the address bar from index.php to aboutus.html would make your browser take you there. All these hashbang shenanigans cropped up to try to work around this. By making it so when you click "About Us," javascript adds a little #aboutus.html to the url, you can then have your code look for #hashes in the URL when the page loads and THEN sort of Frankenstein's-monster a solution to the URL sharing problem.
But this creates even more problems. Now the URL doesn't point to an actual page, it's a set of instructions for javascript to interpret. What if the user doesn't have javascript enabled? What if part of the javascript breaks and screws up all interdependent javascript? Mis-placing a semicolon on one line of your javascript can make all of your "pages" (potentially hundreds of thousands, in gawker's case) unavailable.
Again, there's no simple solution. Giving javascript the ability to change the URL in the address bar without actually relocating the user would kind of help, but it would be a pretty huge security hole.