Tips and Tricks in a world of Mix

 

A full solution is here- https://gist.github.com/921920

 

// force certain pages to be refreshed every time.  mark such pages with
// ‘data-cache="never"’
//
jQuery(‘div’).live(‘pagehide’, function (event, ui) {
    var page = jQuery(event.target);

    if (page.attr(‘data-cache’) == ‘never’) {
        page.remove();
    };
});

// for pages marked with ‘data-cache="never"’ manually add a back button since
// JQM doesn’t.  this is *okay* because we know the browswer history stack is
// intact and goes to the correct ‘back’ location.
// specified back button – however!
//
jQuery(‘div’).live(‘pagebeforecreate’, function (event, ui) {
    var page = jQuery(event.target);

    if (page.attr(‘data-cache’) == ‘never’) {
        var header = page.find(‘[data-role="header"]’);

        if (header.jqmData("backbtn") !== false && header.find(‘[data-rel="back"]’).size() == 0) {
            var back = jQuery(‘<a href="#" data-icon="back" data-rel="back">Back</a>’);
            header.prepend(back);
        };
    };
});

 

but I didn’t want to change every page , so –

On pageHide of my current page I remove itself from Dom object.

 

$(‘#pageIndex’).live(‘pagehide’, function (event, ui) {
    var page = jQuery(event.target);

   // if (page.attr(‘data-cache’) == ‘never’) {
       
page.remove();
   // };
});

Then you can apprach the page from scretch :

 

$.mobile.changePage("index.html");

from everywhere , and it’ll rebuild it !

Advertisements

Comments on: "Jquery Mobile remove page caching solution" (3)

  1. I get an “Error Loading Page” after doing this. Are you doing something else that makes these pages get reloaded on demand into the DOM after removing them?

    Like

  2. Shrkant said:

    Thanks Greg,

    This post helped me to avoid caching while changing the page.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: