4 ms·
You don't need to use hashbangs or fragments for this, you just implement some javascript to not visit links, but change the page with javascript, then change t
by keeperofdakeys 15y ago
You don't need to use hashbangs or fragments for this, you just implement some javascript to not visit links, but change the page with javascript, then change the url to the new one. Your links are still linkable, and you can still have dynamic pages. As for search engines, if the site is a web app, they shouldn't be indexing it.
Look at http://tumbledry.org/2011/05/12/screw_hashbangs_building http://tumbledry.org/2011/05/12/screw_hashbangs_building for how this would work, it was on HN yesterday. Visit just http://tumbledry.org http://tumbledry.org to see how this can work.
- wahnfrieden 15y agoOne additional challenge is that POSTing a form will result in the whole page reloading by default. You will need to take this into consideration if you're supporting dynamic pages with graceful fallback. I wonder if there's some JS library that transparently "fixes" issues like this for single-page sites with graceful degradation. Form handling, link click events, redirects, etc.
- riobard 15y agoThere is no way you can change the URL (not fragments) without refreshing the page (a.k.a single page app) if the browser doesn't support history.pushState. IE doesn't. That's why people are stuck with hashbangs.
- wahnfrieden 15y agoThe parent's method is still the best way as long as you do it by using replaceState or pushState where available, falling back to modifying the hash. This way, if Javascript is off, links in the HTML still work. (I suspect this is what he meant too, since changing links to modify window.location via Javascript provides no practical difference.)
- riobard 15y agoThe parent said “You don't need to use hashbangs or fragments for this”. I'm just pointing out there is no way to _not_ use fragments and still have a single page app. I do agree that we should probably leave IE users to reload pages and provide graceful degradation. Modern browser users will enjoy the benefit of no refreshing on single page app. However, for some, this is not an option.
- diamondhead 15y agoFOA, it's not a good idea to code for search engines. Secondly, pushState is useless for single page apps. It's not all about changing the url, what's the way of handling that urls with just a single HTML document? To make index.html 404 page? What about the browser cache?