3 ms·
They are not arbitrary separations, they are very real. When a user navigates from the URL bar or from a link on another site the browser requests a specific l
by MatthewPhillips 15y ago
They are not arbitrary separations, they are very real. When a user navigates from the URL bar or from a link on another site the browser requests a specific location from my server. Since I'm already serving the browse HTML it makes sense to render my templates at the same time. It doesn't make sense to send only a generic template and then have the popstate trigger an XHR request for some JSON which gets rendered by a javascript template library. That's extra and unnecessary.
What are you suggesting? That I request the entire html doc at every popstate event?
- masklinn 15y ago> When a user navigates from the URL bar or from a link on another site the browser requests a specific location from my server. Since I'm already serving the browse HTML it makes sense to render my templates at the same time. It doesn't make sense to send only a generic template and then have the popstate trigger an XHR request for some JSON which gets rendered by a javascript template library. That's extra and unnecessary. Wait, I might have misunderstood something here: do you mean `popstate` is triggered when users arrive on your site from an other one or from nowhere? On initial loading? As in, it's triggered by navigation between different domains, not just in-domain navigation?
- MatthewPhillips 15y agoCorrect.
- masklinn 15y agoWould you happen to be using Chrome? edit: Try checking the `state` attribute of your event object, it should only be set (therefore truthy) for history entries created via pushState, urls being navigated will not have a state.
- MatthewPhillips 15y agoYep. Chrome bug?
- masklinn 15y agoMay be a chrome bug[0] or a spec bug/weirdness[1]. See edit, try checking for the state attribute on your event object to filter out spurious popstate events. An other option would be to use a shim library (History.js) handling that kind of crap (and smoothing out implementation details issues) for you. [0] http://www.google.com/support/forum/p/Chrome/thread?tid=28edce84cd40d581&hl=en http://www.google.com/support/forum/p/Chrome/thread?tid=28ed... [1] http://hacks.mozilla.org/2011/03/history-api-changes-in-firefox-4/ http://hacks.mozilla.org/2011/03/history-api-changes-in-fire...
- MatthewPhillips 15y agoYep, I was doing it wrong. You're supposed to pass a state object as the first parameter, I was passing null. So this fixes 2 things, prevents me from having to do XHR on initial page load AND I don't need to do an XHR on back/forward navigation either, I can just use the state object to store my data. Awesome!
- masklinn 15y agoGood to hear.
- MatthewPhillips 15y agoI just tried this and state is always null for me. edit: it was because I was passing null on pushstate. I can change this. Thanks!