rockinaway Posted July 20, 2012 Share Posted July 20, 2012 A simple question - which do you think would be best to use for any dynamic content? Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/ Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 From what I understand, pushState is in the HTML5 spec. Since the HTML5 spec is still in draft, it's hard to argue that it's an ideal solution on it's own. Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363085 Share on other sites More sharing options...
rockinaway Posted July 20, 2012 Author Share Posted July 20, 2012 I see, so you would recommend sticking with hashchange at the moment? Â Although I have seen quite a few big websites e.g. Facebook using some type of pushState to alter the URLs. I assume they have a fallback if it fails? Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363088 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 That would be my guess. I doubt they've abandoned support for IE9. Â http://caniuse.com/#search=pushState Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363090 Share on other sites More sharing options...
rockinaway Posted July 20, 2012 Author Share Posted July 20, 2012 Hmm well looking at the support it seems that it is the thing for the future and is supported by most of the latest browsers. Wouldn't you recommend implementing it now rather than later? I mean the only two that don't support it are mobile versions which currently I don't aim to directly support anyway. What are your thoughts on this? Â And a note, brilliant website there! Never used it before - extremely useful thanks! Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363093 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 If you don't mind programming a fall-back, or simply abandoning support for IE9 users I don't see a problem with implementing pushState. It's really up to you - how much work you want to do and how accessible your site will be. Â I personally don't bother with coding HTML5-specific behaviour because it's still in draft, and I will generally have to program fall-back functionality anyways. That's my preference though... I don't get paid to be on the bleeding edge of web standards, otherwise I probably would Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363098 Share on other sites More sharing options...
Adam Posted July 20, 2012 Share Posted July 20, 2012 Chrome is now the most used browser, which updates automatically, so you could assume that the majority of users on the internet now have decent HTML5 support. Personally I would implement state, but hijack links/forms and provide non-JS/HTML5 fall-backs, instead of implementing it as the default action. The hardest part is getting your head around the state API, adding the fall back is easy. Although there's plug-ins and scripts around that make using the state API a doddle! Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363156 Share on other sites More sharing options...
rockinaway Posted July 21, 2012 Author Share Posted July 21, 2012 Yeah I've started using the History.js plugin which helps with cross-compatibility too. As for a fallback, I'm not entirely done with adding one and not sure if I will add one because most support state. What do you mean by 'hijack links/forms'? Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363238 Share on other sites More sharing options...
Adam Posted July 21, 2012 Share Posted July 21, 2012 I think it's a good idea to put in fall backs. By "hijacking", I meant write the site as normal. Normal links, normal forms, etc. Then write some JS to literally hijack every link and form within the page to use your push state handle instead of the default action. Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363272 Share on other sites More sharing options...
rockinaway Posted July 21, 2012 Author Share Posted July 21, 2012 Okay so if I was to put in fallbacks, how should I go about it? Any tips? Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363284 Share on other sites More sharing options...
Adam Posted July 23, 2012 Share Posted July 23, 2012 Don't think of it as fallbacks. Just write your site normally, then add some JS that will takeover the links/forms and alter the normal behaviour. Just be sure to detect if their browser supports push state first, so you're not hijacking links and then not updating the URL. Â You could implement this as a nice, clean object. Call it "Page" for example. It would handle the generic loading of URLs through POST or GET requests (i.e. form submissions or just requesting a URL), and loading into the DOM. You could also add a method that allows you to define "page load behaviours", so as each page is loaded you loop through a set of callbacks that re-apply click binds and such -- this would probably be more efficient than using live() or on(), and would also keep the generic page logic separate from the individual, page specific behaviours. Â You could implement it really nice, just try and keep away from lumping everything into one file and it all getting chaotic. Try and keep the logic separate, otherwise it will become harder and harder to maintain. Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363846 Share on other sites More sharing options...
rockinaway Posted July 24, 2012 Author Share Posted July 24, 2012 Okay thanks, I think I have an idea what I can do. Is there any place (emulators etc) where I can test old <HTML4? Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363952 Share on other sites More sharing options...
Adam Posted July 24, 2012 Share Posted July 24, 2012 Ha erm.. older browsers? I would just download a few VMs to recreate the main environments you want to test. Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363957 Share on other sites More sharing options...
rockinaway Posted July 24, 2012 Author Share Posted July 24, 2012 What if, for older browsers, instead of the pushState I just set it so the browser actually redirects or goes to that URL that would have been set by pushState? Seems too simple to be valid :s Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363967 Share on other sites More sharing options...
Adam Posted July 24, 2012 Share Posted July 24, 2012 That's what I've been saying to do? Only use push state if their browser supports it, otherwise just do everything as normal. Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363976 Share on other sites More sharing options...
rockinaway Posted July 24, 2012 Author Share Posted July 24, 2012 Haha thank you, just wanted to check! It seemed too simple to be the way forward! Quote Link to comment https://forums.phpfreaks.com/topic/266007-hashchange-or-pushstatepopstate/#findComment-1363981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.