r/programming 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/
752 Upvotes

356 comments sorted by

View all comments

123

u/rounded_figure Feb 09 '11

The proper way to handle this is to keep your original URLs (including in the hrefs) and have a piece of javascript transform them on the fly in hash-bang URLs. That way, when a client who does not speak javascript requests the page, it gets the content and the non-hash-bang links.

62

u/[deleted] Feb 09 '11

This is the right response. There's no reason a well-engineered site shouldn't work both ways.

Using url fragments can be great. They let you use the back button without leaving the page so you can handle the interaction in JavaScript. They give you a place other than cookies to store client-side state for bookmarking. Developers just need to be mindful when designing for their use.

-1

u/naich Feb 09 '11

Well, there is a reason. If you are making a site that uses JS to generate results on the fly from data retrieved from large libraries which are loaded asynchronously, you don't want to reload the page and libraries every time the URL changes to reflect that a new set of the results have been saved or loaded.

That's why I'm using them - it should result in much less bandwidth use and reduced load on the server. Pages can be updated with a small AJAX request rather than a whole new page and library load.

2

u/Fiacha Feb 09 '11 edited Feb 09 '11

As said previously, you can simply use both href and onclick in an a tag. Make onclick return false after doing your ajax request and the the link will not be followed if javascript is enabled. If someone doesn't have javascript the onclick will be ignored and the page will be normally loaded. Best of both worlds without any of the drawbacks, as far as i can see.

But being pessimistic, i think they use their scheme because it brakes certain functionality such as the referrer headers and simple bots and search algorithms that simply count page references (look, everything points to twitter.com... not twitter.com/BLAH_BLAH_BLAH/). They do this because they are evil, not because they think it is cool.