Unfortunately, when the user navigates backwards they are going to a cached version of the page...it's not a bug, it's done by design. This allows browsers to load pages almost instantaneously.
Here's the problem, because the browser is loading the page from a cache the page is technically never "loaded" and set to "ready"...ie, the jQuery $(document).ready() event is never fired. You can see this by typing console.log(1); immediately inside the event. It'll never fire.
I'm actually working on a work around for my own project. There are two things I've done that work so far:
1) Don't use $(document).ready(). As long as the script is at the bottom of the page, all the elements should be there for you to access anyways...not to mention you are building elements with jQuery so it's not a biggie.
2) Refresh the page manually with window.location.reload or something
[EDIT]
Another workaround I haven't tried is to check the hash of the url with javascript
Assuming you have a single page application that loads different content based on the hash, you could poll the hash, if it changes, refresh the page. This is ugly...really ugly, but it would work. Something like this:
Code:
var hash = location.hash;
setInterval(function()
{
if (location.hash != hash)
{
console.log("URL HAS CHANGED!");
hash = location.hash;
}
}, 100);
Bookmarks