11 ms·
Breaking the web with hash-bangs
- waqf 16y agohttp://news.ycombinator.com/item?id=2195280 http://news.ycombinator.com/item?id=2195280
- Terretta 16y agoChuckle ... Clean URL blogger doesn't fixup his own URLs!
- timb 16y agoNewer browsers ( http://caniuse.com/#search=history http://caniuse.com/#search=history ) can manipulate the url without needing the #! hack.
- raganwald 16y agoTo be specific, it's just the # hack, or fragment hack if you like. The bang leading the fragment is a Google-specific thing to help the Googlebot crawl your content. http://stackoverflow.com/questions/3009380/whats-the-shebang-in-facebook-and-new-twitter-urls-for http://stackoverflow.com/questions/3009380/whats-the-shebang...
- Yaggo 16y ago<strike>No, timb was referring to HTML5 history api. It makes possible to alter the path component of a URL by javascript, eliminating the need for # hack. Try browsing repositories on github with WebKit-based browser to see a real world example.</strike> (sorry for my misreading)
- ehsanul 16y agoAnd raganwald was referring to the '#!' hack, since it's really just the '#' hack. He wasn't addressing the history api.
- itsnotvalid 16y agoHowever all those IE users out there would not have that API. I remembered that facebook's starting to use that API already. The solution with "mangled" URL seems to force a reload on every new request to lifehacker as well. Just like what Facebook did with the hash-reload.
- mckoss 16y agoThanks for the link. I had not realized that pushState would allow for URL address change w/o reloading the page. Unfortunately the support is far from ubiquitous (Firefox support requires the current beta). I think what the author of this diatribe fails to understand is that the separation between the part of a site that uses client side navigation, vs the part that uses sever side navigation is an architectural design choice - not an aesthetic choice of how a developer wants their URLs to look. Client side navigation has performance benefits, ability to use web apps offline, etc. These are all valid reasons to choose to use it. It may not be ideal that the end user is exposed to that detail by breaking the URL up between the "server part" and "client part" separated by the # character. But that's where we are today in browser design. I don't buy the argument that the # scheme makes a web site more fragile. You can break the server side of your app just as easily as you can break the client side.
- raganwald 16y agoI accept the brittleness of a content-oriented site switching to a javascript-driven SPI implementation, however I'm confused by the assertion that the strongest reason to switch is because it's cool. I can't speak for Gawker, but some sites may switch because they want the browser to do more of the rendering work, such as rendering templates. Others may want to avoid the overhead with a full page refresh as users navigate the site. The author clearly dislikes what's going on, and the post would be stronger if he simply stated the disadvantages and let others speak to the benefits rather than putting up a strawman and claiming that people implement this sort of site because it's cool.
- bluesmoon 16y agosome sites may switch because they want the browser to do more of the rendering work, such as rendering templates. Others may want to avoid the overhead with a full page refresh as users navigate the site Both of these can be achieved using progressive enhancement. There is no technical reason to include it in the page itself.
- daleharvey 16y agothere are technical problems with progressive enhancement, the latency between page load and progressive enhancement being applied being a fairly obvious one, the other is the providing full html fallbacks combined with progressive enhancement can be very complicated and time consuming, its very easy to see time when time to live wins out over semantic correctness hopefully html5 pushstate will alleviate a lot of the complications with providing full fallbacks
- bluesmoon 16y agothe latency between page load and progressive enhancement being applied shows up primarily if you load your JavaScript at the bottom of the page. Now I know that this is what Yahoo!'s performance rules suggest, I was on the team that made those recommendations. They made sense between 2006-2009, but browsers have improved significantly since then and that rule isn't necessarily true any more. You can load scripts in the head of your document without any of the blocking issues we saw in the past. You can even do multiple scripts in parallel to reduce download latency. See my <a href="http://calendar.perfplanet.com/2010/thoughts-on-performance/>thoughts http://calendar.perfplanet.com/2010/thoughts-on-performance/... on performance</a> on the 2010 performance advent calendar.
- evandavid 16y agoFor the time being, I will personally continue to build #!-only websites, designed exclusively for javascript enabled browsers. Maintaining two versions (along the guidelines of progressive enhancement) is just too much work (maintaining and testing html view templates as well as jQuery or moustache templates) considering that so few people lack javascript. I wouldn't let a release go live without running a selenium suite across it in any case. My perspective would be different, I imagine, if I worked on a large team that could 'afford' to take the progressive enhancement route.
- TrollBait 16y agoAre you trolling or just a lazy jackass?
- evandavid 16y agoNot trolling. But I admit that I'm overstating my position a little bit to see if any interesting discussion comes of it. The reality of my current situation (a one, sometimes two person team) has meant that I have indeed been following the convention I just described. That's not to say I want to, but as I mentioned, I will probably continue to for the foreseeable future without too much hesitation.
- ehsanul 16y agoNote the account's name, 'TrollBait'. Brand new too. If he keeps those kinds of comments up, he'll be banned in no time. On the other hand, I'm impressed how you just ignored TrollBait's insult and just replied in an absolutely normal manner.
- afhof 16y agoI take almost the polar opposite approach to you, always providing a safe fallback to plain ol' HTML. I feel its a defensive style and doesn't provide a single point of failure. I run Noscript since it makes most pages load much faster. No offense, but I don't want to run your code, I'd rather read your content.
- jbermudes 16y agoLooks like gawker sites show up pretty much empty with javascript turned off, and on top of it there's no warning that it has to be turned on? What ever happened to graceful degradation? Give me 1996 text only if you have to, but please, don't break the web by forcing javascript. Even Gmail, the poster child for javascript/Ajax detects that you have it disabled and shows you an HTML-only version.
- nathansobo 16y agoPlease. I for one am using the fragment hack to build a richer user experience on a widely available platform. The interactions I am building wouldn't be possible without it (or the HTML 5 pushState replaceState equivalents). Rendering my content on the client in JavaScript makes me a lot more productive, and the interactions I facilitate on my site would be impossible without it. The implementation choices of a single web site cannot "break the web". I trust that the author of this post has a lot of experience and also valuable things to say about building accessible sites, but accessibility and graceful degradation aren't the only god in my pantheon.
- hybrid11 16y agoWe had a similar problem with our site, and we solved the issue by using <a id="linkID" href="pathToContent">title</a> links with a jQuery event handler that prevents the default behavior of the link. With this implementation, when the link is clicked the appropriate content is served through an Ajax call, and the crawlers are able to index the content. You can see it in action here http://lynkly.com http://lynkly.com
- pnathan 16y agoI like the smooth two-column layout and flow. It's very high class.
- deleted 16y ago[deleted]
- pkandathil 16y agoYeah I found the jquery solution works best. Th href is for the crawler and for your website you override the onclick. good one @hybrid11
- antimatter15 16y agoI was building an app that used pushState/replaceState recently instead of the hash bang syntax, but getting content navigation isn't easy. For example, when attaching the event handler to the links, you have to be careful not to make it trigger on middle or right clicks and you have to keep track of the scroll state so going back keeps the same behavior and also to take a copy of the previous selected text. Without all of that, intra-page navigation feels unnatural and uncanny.
- mcantor 16y agoHTML5 pushState/replaceState is the "correct" way to do this for compliant browsers, though... right?
- strager 16y agoGood points, but it seems some of that (scrolling, selection, form data, etc.) should be left to the browsers to fix/implement/deal with. Granted, it is a really bad user experience. Seems like this should be made a JS library in the meantime. (Hint, hint. =])
- burgerbrain 16y agoCan someone explain to me why a site like lifehacker even needs javascript at all, let alone so much? It's a blog, presumably it's value should come from the value of it's textual and pictorial content. It's just nuts that I have to burn so much CPU just to read some text.
- garry 16y agoThe web is evolving to provide media experiences that are lower latency and much more exploration oriented. No page reloads and greater interactivity are the first step.
- burgerbrain 16y agoAll of that adds exactly zero to the actual content of the blog. You know, 'content', the stuff I actually visit blogs for. Furthermore, I've never been annoyed at page reloads while reading a blog. Now their shitty transition crap?... There is nothing "lower latency" here.
- silversmith 16y agoSending a e-mail does not add any real 'content' over telegraphing the same message. It's just a change of presentation layer. I still would rather send e-mails. And the same way I would rather create JS-driven sites. It allows me to be more creative with the presentation, while staying in the comfort zone of HTML/CSS/JS. Offloading work from my servers to the computers (that, based on my experience, are near-idle while browsing) of end users is a nice benefit. Oh, and I would disagree about the 'There is nothing "lower latency" here' statement. I visited lifehacker.com out of curiosity, and noticed something: with JS navigation, I could scan headlines in the sidebar while the article was loading, something I would not be able to do while a 'traditional' page was rendering. Of course, it's not a general rule. There are projects where you support IE6/7, and then there are projects where you don't give a damn whether it works for anything but edge versions. Same with using JS as presentation layer.
- 16y ago
- MichaelApproved 16y ago>Being dependent on perfect JavaScript You're almost always dependent on perfect code to keep your site running, be it server side or client side. If code breaks on the server side you're just as screwed.
- shabda 16y agoServer side code runs on one machine. Client side needs to run on many OS/Browser/Plugins combo.
- btilly 16y agoThe key difference is that the JavaScript approach makes you dependent upon third party ads being served correctly, while the standard HTML approach makes bad code in third party ads just affect the display of those ads. That third party dependency is a significant difference.
- drdaeman 16y agoEven not considering that HTML5 History API, is it hard to just consider "/1234/spam" and "/#!1234/spam" synonymous and use the latter when you navigate with JavaScript enabled? I.e.: 1. You visit "/1234/spam", and get served full HTML page with some (optional) JavaScript for progressive enhancement. 2. You click on "/4321/ham" link, but JavaScript hooks it up and replaces URI with "/#!4321/ham" (if your browser don't support HTML5 history API, of course). Yes, there is one full-page reload. 2.1. (Alternative) Or - even better - you can be redirected to "/#!1234/spam" on step 1, so you won't notice the glitch on your first click. 3. You continue to navigate with AJAX, now without reloads. You can bookmark pages and so on (and if you somehow happen to lose JavaScript support you could just remove "#!" to get a valid URI). Very simplified implementation cost: 1. `$("a[href]").attr("href", function() { return this.href.replace(/^\/(?!#)/, "/#!"); });` on every page 2. `if (location.pathname === "/" and location.hash.match(/^\/#!/) { $("#content").load(location.hash.replace(/^#!/, "/") + "?format=content-only"); ... }` on / page. 3. Ability to return undecorated ("article-only") content on `/1234/spam?format=content-only` requests.
- Pewpewarrows 16y agoYou just described exactly what you're _supposed_ to do in a progressively-enhanced single-page Javascript application. Build the existing site first without a single line of js, develop the hash-bang/HTML5 history syntax on top of it, and replace the links if javascript exists. The Gawker family of sites failed at doing all of this.
- carbonx 16y agoDid they do any sort of beta testing on this before they rolled it out?
- billswift 16y agoHash bangs obviously aren't the only way to break web pages; has anyone else noticed that the current Google homepage has broken the keyboard shortcuts, at least in Firefox? You can't (or at least I can't) access the menu with the Alt key now.
- metageek 16y agoWFM. (Firefox, 64-bit Linux nightly build.)
- eapen 16y agoEven worse, they dont appropriately use the canonical meta tag.
- colanderman 16y agoProposal: extend Transfer-Encoding to allow gzip encoding of multiple responses in a persistent connection as if they were a single stream. This way, a browser which expects to request multiple pages from a site can keep the connection open, and the repeated content on each page will be gzipped into oblivion. The problems I see is that this would require both server and browser support, and that leaving persistent connections open for minutes could be problematic.
- metageek 16y agoDoesn't SSL do compression? (Most good encryption systems do, because compression strips out the redundant data that codebreakers need.) If so, you should be able to do persistent connections over HTTPS, and get the whole stream compressed.
- poink 16y agoThe more complex your site gets, the harder making /foo/bar => #!/foo/bar dance becomes. This is hampered by the fact that, when you bring these issues up with business folks, it'll probably go something like this (from experience): 1) How many of our users will be affected? 2) How much harder (i.e. how much longer) will it be to do it right? 3) Don't we depend on JS to inject ads anyway? Ads are the whole reason anybody's paying for this... When you truthfully answer #1, if #2 is more than about 5 minutes, nobody's going to budget for it. Overall, the hash-as-URL argument is hampered by the fact that Gawker is a prime example of going single page just because you can. Other than fancy page->page transitions, I don't see what their new setup buys them.
- dennisgorelik 16y agoIt looks like URL of that article is case-insensitive and page does not specify canonical URL. Both: http://www.isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs http://www.isolani.co.uk/blog/javascript/BreakingTheWebWithH... and: http://www.isolani.co.uk/blog/javascript/breakingthewebwithhashbangs http://www.isolani.co.uk/blog/javascript/breakingthewebwithh... render the same content, and <link rel="canonical"> does not exist in source code of that page.
- kehers 16y agoIn the first place, y should a news publishing site even use hash-bang url? U r not a web app built on ajax