Backbone.js 0.5.0 Released (with pushState)
11–20 of 38 posts
Re: Backbone.js 0.5.0 Released (with pushState)
#12Earlier quoted context omitted.
> Which is a problem because if they type it in directly I want to render on the server Why? What difference does the precise way they navigated to the URL make? > if they hit the back button I want to do xhr. Most back buttons have a popup menu which let users go to a completely arbitrary url they've already seen, they're not limited to the very last page. They can also hit the button several times to go back to the…
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 b…
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?
Re: Backbone.js 0.5.0 Released (with pushState)
#13Right now I'm doing pushState manually and I have a bug that I can't figure out. popstate happens whenever history changes, including when the user types my URL in and hits enter. There doesn't appear to be a way to differentiate between hitting the back button and going to my URL directly. Which is a problem because if they type it in directly I want to render on the server, if they hit the back button I want to do…
pushState is called with three arguments, {state, pagetitle, url}
If the user navigates directly to a URL, state will be null or undefined, in which case your onpopstate handler should not execute the XHR transition.
I'd recommend testing in both Firefox and Chrome, as each browser handles onpopstate events differently.
Re: Backbone.js 0.5.0 Released (with pushState)
#14Earlier quoted context omitted.
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 b…
> 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 unne…
Re: Backbone.js 0.5.0 Released (with pushState)
#15Earlier quoted context omitted.
> 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 unne…
Correct.
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.
Re: Backbone.js 0.5.0 Released (with pushState)
#16Earlier quoted context omitted.
Correct.
Would 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.
Re: Backbone.js 0.5.0 Released (with pushState)
#17Earlier quoted context omitted.
Would 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.
Yep. Chrome bug?
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=28ed... [1] http://hacks.mozilla.org/2011/03/history-api-changes-in-fire...
Re: Backbone.js 0.5.0 Released (with pushState)
#18Earlier quoted context omitted.
Correct.
Would 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.
edit: it was because I was passing null on pushstate. I can change this. Thanks!
Re: Backbone.js 0.5.0 Released (with pushState)
#19Earlier quoted context omitted.
Yep. Chrome bug?
May 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=28ed... [1] http://hacks.mozilla.org/2011/03/history-ap…
Re: Backbone.js 0.5.0 Released (with pushState)
#20I'd be curious to hear from anyone who thinks that this sort of parallel hashchange/pushState support is a bad idea. It should prove to be controversial at the least. * http://www.documentcloud.org/public/#search/guantanamo * http://www.documentcloud.org/public/search/guantanamo People who don't care much about Internet Explorer support often say to just use pushState, and let IE users endure full page refreshes ...…