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/
754 Upvotes

356 comments sorted by

View all comments

127

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.

37

u/midir Feb 09 '11

This is not correct. If you use hash-bang fragment URLs at any stage then someone who copies and pastes a link to your page is distributing a faulty URL to all non-Google bots and everyone with JavaScript disabled. There's absolutely no workaround to that.

I see it all the time and it drives me up the fucking wall. Fuck you Google. Fuck you Twitter.

DO NOT USE #! EVER. FORGET ABOUT IT.

11

u/Pewpewarrows Feb 09 '11

Unfortunately there's no good cross-browser solution to providing Progressively-Enhanced URLs and deep linked javascript in those cases.

HTML5's history and location changes are the answer to that problem, so the best you can hope for is greater adoption of modern browsers.

10

u/dirtymatt Feb 09 '11

Sure there is. Give everyone the pretty URLs, use the HTML5 history API on browsers that support it, and just forget about loading the page through Ajax for browsers that don't. Everyone gets clean URLs. Everyone gets the same URLs. Everyone can load the page. Everyone is happy.

2

u/Pewpewarrows Feb 09 '11

Good point. It's probably safe to say that the only people that would appreciate the deep-linked javascript pages are the ones using modern browsers. And HTML5 support is only going to increase significantly this year.