Allow first page to be deleted when Dom caching is disabled #3249

Description
Apparently any FIRST page you access, will be kept in the DOM, even if dom-cache is set to false (well, it's already false in the configuration..).
Example:
I access this page 1st:
<body class="ui-mobile-viewport">
<div class="ui-page ui-body-c ui-page-active" data-dom-cache="false" data-role="page" data-url="/Mobile/User/Home" tabindex="0" style="min-height: 965px;">
<div class="ui-loader ui-body-a ui-corner-all" style="top: 482.5px;">
</body>
Now i go to this page:
<body class="ui-mobile-viewport">
<div class="ui-page ui-body-c" data-dom-cache="false" data-role="page" data-url="/Mobile/User/Home" tabindex="0" style="min-height: 965px;">
<div class="ui-loader ui-body-a ui-corner-all" style="top: 482.5px;">
<div id="user-search" class="ui-page ui-body-c ui-page-active" data-role="page" data-url="/Mobile/User/SearchView" data-external-page="true" tabindex="0" style="min-height: 965px;">
</body>
And now if i click to go back to the first page, even tho i'm saying i do not want any dom cache, the first page will simply be displayed again, and so i get a cached copy instead of a new one.
I can navigate all over the entire site, and it will always be kept in the dom as invisible, and then just be displayed if we ever navigate back to it again. All other pages get added and removed from the dom normally as we navigate around from page to page, it's just this 1st page.
If i would have navigated to the 2nd page first, then this page would have been eternally cached in the dom.
Activity
toddparker commentedon Dec 12, 2011
Yes, as of 1.0 the initial page isn't removed. The rule is that only pages pulled in via Ajax are removed so this is working as planned. We're going to revisit some topics around this in upcoming releases but it's not a bug per se.
ghost commentedon Dec 13, 2011
The real problem for us is that we need to be able to control which pages are cached and which pages must be refreshed and when.
With this behavior, basically any page on your site, will be cached indefinitely if the user happens to access that specific page 1st. .. not really a problem if the user always happens to access some kinda static placeholder page, but a lot more problematic if you access your profile page, change some stuff and go back to you profile page and see nothing has changed (well ..just one example among many use cases you will find on any dynamic site).
So for now i had to toss this my start up code:
For us it was either this solution, or setting ajaxEnabled = false on the entire site (which is kinda a bummer)
Maybe you have a better suggestion ?
tnx
toddparker commentedon Dec 14, 2011
This is something we've been discussing. I just updated the title to be clearer and flagged this as a feature request. Mind link to this from the feature request wiki page here?
ghost commentedon Dec 15, 2011
Link away :)
minfrin commentedon Mar 22, 2012
I would definitely mark this as a bug.
In our case, we have one page with a list of things, which link to subpages describing each thing. If you land on a subpage describing each thing instead of the list page (this is trivial to do - be on the subpage and press browser reload and now the subpage is your main page), and then use on-page functionality to update the thing which results in an error message (the error message being rendered as a proper jquery mobile page), from that point on the error message is cached, because it's the body of the opening page. Until you reload the page, that cached error message is all you see.
Ideally, all pages need to behave identically with respect to caching, including the opening page, otherwise all sorts of weirdness ensues when the end user presses browser reload.
The workaround from itechnology above works for me, but ideally it shouldn't be necessary.
adammessinger commentedon May 25, 2012
I also ran into this problem and scripted a fix that keeps the first-loaded page in the DOM but refreshes it when you return to that page: https://gist.github.com/2779268
You can find more discussion on this problem and my attempts to work around it on issue #4050.
xshhe82 commentedon Aug 14, 2012
orkarlinsky commentedon Aug 31, 2012
Had the same problem and LUCKILY got here to find the solutions. I strongly urge you to push this fix to 1.2.
It's a really buggy behavior and the fix is so simple it would be a shame not to. Also, it could be hard for the developer to understand what the problem is, from his point of view sometimes the page is being cached and sometimes not, it appears to be totally random and it's hard to notice the "first page" subtle difference.
jaspermdegroot commentedon Sep 3, 2012
@orkarlinsky - If you read the thread of #4050 you will understand the "fix" is not that simple as it appears.
Golodhros commentedon Oct 10, 2012
Both solutions from @xshhe82 and @itechnology woked fine at first, but it happens that when you navigate to a page, and come back to the first one with some android devices (Kindle Fire HD and Samsung Galaxy Tablet 10.1 at least) it crashes the application...
Did anybody have this same problem?
adammessinger commentedon Oct 10, 2012
@Golodhros, can you give this a try and let me know if it doesn't work for you? https://gist.github.com/2779268
See my comments on #4050 (starting here) for some of the issues I found and fixed while creating that code -- yours may be among them.
Note: That Gist was written for jQM 1.1.0 and hasn't yet been tested with anything newer. It also assumes you're using jQuery 1.7.x. If you aren't, try tweaking it to replace my use of .on() with .bind().
renhart commentedon Jan 18, 2013
Is there a solution to this problem for jQM 1.2? Without a work-around it's a show stopper for dynamic sites where a visitor may start from different pages, or if the user clicks the browser's reload button on a page.
toddparker commentedon Jan 18, 2013
We'll re-evaluate this for 1.4.
28 remaining items