How does one disable Caching in jQuery Mobile UI


<div data-role="page" data-cache="30"> 
<div data-role="page" data-cache="never">
<div data-role="page" data-cache="false"> 
<div data-role="page" cache="false">

Nothing seemes to work... so at the moment I'm fixing the problem on the server-side via...


I don't want to disable the AJAX just the caching. There has to be a better way though... am I missing something?





Thank you for the answers guys, and even though they didn't quite work for me they did point me in the direction to find the code I was looking for.

This is the code that I found on this gentleman's Github Gist.

jQuery('div').live('pagehide', function(event, ui){
  var page = jQuery(;

  if(page.attr('data-cache') == 'never'){

There is also a back button code in that Gist, but I don't seem to need it really as my back button seems to work just fine...


Have you tried to overwrite the default value ?

$(document).bind("mobileinit", function(){
    $ = false;

This works for me


Page caching is now off by default in jQM RC1. See the extract below from the jQM website about page caching:

If you prefer, you can tell jQuery Mobile to keep previously-visited pages in the DOM instead of removing them. This lets you cache pages so that they're available instantly if the user returns to them.

To keep all previously-visited pages in the DOM, set the domCache option on the page plugin to true, like this:

$ = true;

Alternatively, to cache just a particular page, you can add the data-dom-cache="true" attribute to the page's container:

<div data-role="page" id="cacheMe" data-dom-cache="true">

You can also cache a page programmatically like this:{ domCache: true });

The drawback of DOM caching is that the DOM can get very large, resulting in slowdowns and memory issues on some devices. If you enable DOM caching, take care to manage the DOM yourself and test thoroughly on a range of devices.


Method 1

This disables AJAX


Set ajaxLinksEnabled to false and it will not load and cache those pages, just work as normal links.

Method 2

Second idea is to remove cached elements. You can bind to pagehide event and make it remove the page instead. If not present in DOM, the page will be loaded again.

It can be done with this code as a proof of concept:

$('.ui-page').live('pagehide',function(){ $(this).remove(); });

But it needs a little work. The above code breaks the history. It prooves that you will only be able to use it with pages you intend to be leaves in your sitemap tree. Therefore you have to create a special selector for them or bind it to only certain pages.

Also you can bind to a button's click or mousedown event, get its href, generate page id out of it and find the div by id to remove it before jqm tries to look for it.

I have found no advised way of disabling the cache or forcing loading.


Martin's answer should be the right one in my opinion but jQuery Mobile cache the first page no matter what.

I've opted to "patch" the behaviour of $ = false and data-dom-cache="true"

$(document).on('pagehide', function (e) {
    var page = $(;
    if (!$
        && (!page.attr('data-dom-cache')
            || page.attr('data-dom-cache') == "false")
        ) {

Here's my working solution:

$('.selector').live( 'pagebeforecreate', function () {
    $.mobile.urlHistory.stack = [];
    $.mobile.urlstack = [];
    $( '.ui-page' ).not( '.ui-page-active' ).remove();

I wrote an (original in German) article about that topic, maybe that helps. Link to google translated article


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.