Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

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

Closed
@ghost

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

toddparker commented on Dec 12, 2011

@toddparker
Contributor

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

ghost commented on Dec 13, 2011

@ghost

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

toddparker

toddparker commented on Dec 14, 2011

@toddparker
Contributor

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

ghost commented on Dec 15, 2011

@ghost

Link away :)

minfrin

minfrin commented on Mar 22, 2012

@minfrin

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

adammessinger commented on May 25, 2012

@adammessinger
Contributor

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

xshhe82 commented on Aug 14, 2012

@xshhe82
$(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);
                }
            });
orkarlinsky

orkarlinsky commented on Aug 31, 2012

@orkarlinsky

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

jaspermdegroot commented on Sep 3, 2012

@jaspermdegroot
Contributor

@orkarlinsky - If you read the thread of #4050 you will understand the "fix" is not that simple as it appears.

Golodhros

Golodhros commented on Oct 10, 2012

@Golodhros

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

adammessinger commented on Oct 10, 2012

@adammessinger
Contributor

@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

renhart commented on Jan 18, 2013

@renhart

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

toddparker commented on Jan 18, 2013

@toddparker
Contributor

We'll re-evaluate this for 1.4.

28 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thenewguy@Golodhros@solymosi@toddparker@adammessinger

        Issue actions

          Allow first page to be deleted when Dom caching is disabled · Issue #3249 · jquery-archive/jquery-mobile