Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save hiroprotagonist/921920 to your computer and use it in GitHub Desktop.
Save hiroprotagonist/921920 to your computer and use it in GitHub Desktop.
// 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
Copy link
Author

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

@jschnitzer
Copy link

Thank you this worked very well.

@sjjs1985
Copy link

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
Copy link
Author

Hi sjjs.

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

@brunobraga
Copy link

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
Copy link
Author

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
Copy link

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

Cheers,

@hiroprotagonist
Copy link
Author

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
Copy link

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
Copy link

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">   ...

@markthepixel
Copy link

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