Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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);
};
};
});
@hiroprotagonist

This comment has been minimized.

Copy link
Owner Author

@hiroprotagonist hiroprotagonist commented Apr 15, 2011

This change takes care of the jqm attribute data-backbtn="false"

@jschnitzer

This comment has been minimized.

Copy link

@jschnitzer jschnitzer commented Jul 29, 2011

Thank you this worked very well.

@sjjs1985

This comment has been minimized.

Copy link

@sjjs1985 sjjs1985 commented Sep 8, 2011

is there any way I can create a page in history without them actually visiting? I want to disable the user going back to previous pages but if they do try and go back I want to send them to an error page.
thanks

@hiroprotagonist

This comment has been minimized.

Copy link
Owner Author

@hiroprotagonist hiroprotagonist commented Sep 8, 2011

Hi sjjs.

I dont know. Maybe you more lucky with the jqm forum.

@brunobraga

This comment has been minimized.

Copy link

@brunobraga brunobraga commented Jun 28, 2012

Hei, This did not work for me... where should the data-cache="never" be placed? I tried in the same div with data-role="page", but still I am getting cached data... A little help...

@hiroprotagonist

This comment has been minimized.

Copy link
Owner Author

@hiroprotagonist hiroprotagonist commented Jun 28, 2012

Hey Bruno! This "old" workaround worekd for jqm
versions < 1.0.
Since ajax navigation was totally renewed in 1.0 i am pretty sure
that this gist won't work on versions >=1.0

@brunobraga

This comment has been minimized.

Copy link

@brunobraga brunobraga commented Jun 28, 2012

Shame. Thanks anyway for the feedback... if you have updates (how it's done on newer versions), let us know!

Cheers,

@hiroprotagonist

This comment has been minimized.

Copy link
Owner Author

@hiroprotagonist hiroprotagonist commented Jun 28, 2012

Well, there is a new attribute called "data-dom-cache" which can be true or false. You can use it on pages, dialogs and links. this could be what ur looking for. see the docs:http://jquerymobile.com/demos/1.1.0/docs/api/data-attributes.html .
Once i've suggested to use cache-control properties from the http response header which i think is much more smart but the developers rejected. Let me please know if data-dom-cache is working for you.

@brunobraga

This comment has been minimized.

Copy link

@brunobraga brunobraga commented Jun 29, 2012

Thanks,

I finally got it working and it was a different approach, maybe because I am actually submitting a form (with a button, not link). The page attribute does not work.

I got it working by including the data-ajax="false" into the

tag... May not be the best approach, but it is what I need now (specially under development).

Cheers,

@Rezu

This comment has been minimized.

Copy link

@Rezu Rezu commented Feb 20, 2013

Howdy hiroprotagonist,

I've tried adding data-dom-cache and it's not working...jQM 1.2...any ideas?

I've tried adding data-dom-cache to the page I wish to cache....is the following example correct usage?

Much Thanks!

EX.

    <div data-role="header" data-theme="a">
        <h1>Search</h1>
        <a href="../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
    </div>



<div data-role="content">   ...
@mprogano

This comment has been minimized.

Copy link

@mprogano mprogano commented Feb 27, 2013

I have javascript functions that just run when the page loads, if I run "jqm-data-cache-never" it will remove that orignal page and all the javascript functions that can run, I tried putting the js functions in different on() calls that jQM offers but never seen a result that works,

Any ideas?

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