jquerybrowser-historyjquery-bbq

Support browser back-button with ajax without relying on a hash change?


I'm currently using the jQuery BBQ plugin to enable the bowser navigation buttons to work, but I have a problem in that if a bookmark is saved by a user for one of the pages, say...

www.mysite.com/#page1

when the user returns via the bookmark the full page has to first load...

www.mysite.com/

before the hash part of the url can be used for the ajax call back to complete the page.

To address the problem I've tried creating only a 'skeleton' page on all url calls to the main page so that all 'inner' content is fetched via ajax, but this doesn't seem a great solution.

Does anyone know of any methods/plugins that do not use the 'hash' method to support 'back-button history etc?


Solution

  • The only solution to prevent that double page load is to use the HTML5 History API, which allows you to modify the URL directly, rather than having to deal with hashes.

    As the HTML5 History API is relatively new, all browsers support it differently. You can use History.js to normalise the functionality between browsers.

    To learn more about the problem you are having with hashes, and how hashes compare with the HTML5 History API, read this article.