-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Allow first page to be deleted when Dom caching is disabled #3249
Comments
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. |
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: // INFO: We don't want jqm to keep the first page indefinitely, we need to break the cache, even if we are doing ajax
jQuery(document).bind("pagechange", function (toPage, info) {
if (jQuery.mobile.firstPage && info.options.fromPage && (jQuery.mobile.firstPage == info.options.fromPage)) {
jQuery.mobile.firstPage.remove();
// We only need to remove 1 time from DOM, so unbind the unused event
jQuery(document).unbind("pagechange", this);
}
}); 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 |
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? |
Link away :) |
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. |
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. |
$(document).on("pagechange", function (toPage, info) {
if ($.mobile.firstPage && info.options.fromPage && info.toPage && ($.mobile.firstPage == info.options.fromPage) && !$.mobile.firstPage.is('[data-dom-cache="true"]') && (info.toPage.attr('data-url') != info.options.fromPage.attr('data-url'))) {
jQuery.mobile.firstPage.remove();
$(document).off("pagechange", this);
}
}); |
Had the same problem and LUCKILY got here to find the solutions. I strongly urge you to push this fix to 1.2. |
@orkarlinsky - If you read the thread of #4050 you will understand the "fix" is not that simple as it appears. |
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... |
@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(). |
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. |
We'll re-evaluate this for 1.4. |
+1 for this feature, it is reeeeally needed!!! Could you please re-evaluate it for 1.3? --Thanks |
I'm also running into this issue because I'm using the same id's on different pages. This causes some javascript functions to run the code on the first id and therefore not working on the ones that are visible. |
I had the same issue using 1.3.1. To get around it I just implemented the following: $(document).on("pagebeforechange", function(event, data){
if (typeof data.toPage == "string") {
// If we currently aren't on the home page, and we are navigating to the home page
if ($.mobile.activePage.attr("id") != "home_page" && $.mobile.path.parseUrl(data.toPage).filename == "home_page") {
// Force a page reload
data.options.reloadPage = true;
}
}
}); Probably not the nicest way to do it, but it seems to work for me. |
// Fix caching of first page
$(document).on('pagechange.fixcache', function (event, info)
{
if($.mobile.firstPage.is('[data-dom-cache="true"]') || $.mobile.page.prototype.options.domCache && $.mobile.firstPage.is(':not([data-dom-cache="false"])'))
{
$(document).off('pagechange.fixcache');
}
else if(info.options.fromPage != undefined)
{
if(!($(info.toPage).is('[data-role="dialog"]') || $(info.options.fromPage).is('[data-role="dialog"]')))
{
if(info.toPage.attr('data-url') != info.options.fromPage.attr('data-url'))
{
$.mobile.firstPage.remove();
$(document).off('pagechange.fixcache');
}
}
}
}); |
Closing as feature request. We are going to update the roadmap. If we decide to implement the feature we will set a specific milestone. The ticket will be re-opened when we are going to work on implementing the feature. |
A shame to see something as old and important as this still being around 2 years after initial reporting. Especially since it affects 100% of dynamic sites. To me, if Dom caching is disabled and its still caching the Dom, then it's a bug not a feature. |
+1 for @itechnology This has to be considered as a bug and not as a feature since it is an unexpected and inconsistent behaviour that its very annoying. |
I understand that people want this, but I don't agree that it is a bug. From the beginning it has been documented that only AJAX loaded pages are removed. If adding this feature was a simple change we would have implemented it already, but it is not. |
I understand that since 1.0 many things have probably changed making this harder to fix than most suspect. However I reported this on 1.0 final, and alpha and beta versions did not have this behavior, so i conclude that this was tossed in as a performance enhancement afterthought since it exist since 1.0 final, but did not exist in 1.0 beta. Anyway, enough rant. Jqm is still a pretty cool project |
Very disappointing news - was really hoping it'd be fixed for 1.4 (was actually holding off on a release to find out). Every project has bugs, but this has really been a biggie for us. This one problem has caused more trouble in work-arounds, testing, and user-support than all other JQM bugs/quirks combined. We're sticking with version 1.2 for the foreseeable future because we have a (somewhat) working set of work-arounds and known issues for the initial page loading/caching bug and don't see any enough value in future versions (to justify going through it all again) until this problem is fixed. People are spending a LOT of time on work-arounds, none of which work 100%, and seem to require work-around after work-around themselves. If a real fix is possible, even if it takes a lot of work and postpones other fixes and other features, it would still be a very good investment. Thanks for listening! |
100% agreed. This behavior is just lame. We'd like consistent loading of pages, whether they happen to be the same as the first request or otherwise. about to implement mdgross's hack, out of unfortunate necessity. |
This is a pretty horrible issue to me as well, massively complicating my work with jqm :( Testing around it seems that a simple: Are there any downsides to this I am not seeing so far? EDIT: |
My workaround for 1.4.3 is the following: $(function() { $(document).on("pagecontainerchange", $.mobile.pageContainer, function(event, ui) { if($.mobile.firstPage === ui.prevPage && !ui.prevPage.page("option", "domCache")) { ui.prevPage.remove(); } }); }); |
Hi @solymosi , That will work in some cases but I recommend that you use my "pagechange.fixcache" code above for a number of reasons including checking the DOM cache settings and whether a page is a dialog. |
Updated solution from @mdgross to pagecontainerchange (pagechange is deprecated):
|
This solution worked for me too. |
Hi, |
As of 1.4.4 there is an issue with |
Can someone tell me how I can fire a javascript code written inside a document.ready statement. What I am doing is: submitting some data to second page using HTTPPost method. It loads the second page correctly but fails to invoke the $(documnet).ready(). Thanks in advance! |
@vedbhawsar try to use .delegate() method to attach events to elements now or in the future. |
Since removing the first page no longer works I tackled this problem from another direction and so far the solution seems to work for my use case. I figured I would post it in case it helps anyone else. The idea is that since the first page cannot be removed, the only way to prevent showing stale content on the first page is to generate the first page dynamically and never actually show it again after loading the app.
My endpoint returns a noscript version of the page content and sets data-url to '/initial-page/' when it isn't requested by ajax, so I don't create the initial dummy content in the listener, but it would be trivial to adjust this to create the actual initial page content on the fly. The downside to this approach is that it takes additional time on the initial page load. But it isn't a significant length of time and also shows the user a loading spinner. I am sure with additional tweaking it can be sped up. |
my Solution for 1.4.5 Bug Then use this code which is a modified version of @mdgross
|
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:
Now i go to this page:
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.
The text was updated successfully, but these errors were encountered: