user1692333
user1692333

Reputation: 2597

How to put off cache in JQM when returning to home page?

After page is loaded i press a link and a particular page is loaded. The problem starts when i want to go back to the index page - the page is "cached". It stays in the DOM with display:none or something that, but i need that it would load every time as new, how to do this? I already tried:

Upvotes: 0

Views: 186

Answers (1)

Gajotres
Gajotres

Reputation: 57309

This feature is still a bit buggy, at least data-cache="false".

Solution 1

To disable cashing on a app level you need to do it in mobileinit event, like this:

$(document).bind("mobileinit", function() {
    $.mobile.page.prototype.options.domCache = false;
});

one more thing, a lot of people don't understand this part. Mobileinit event MUST be initialized before jQuery Mobile is initialized, like this:

<script src="jquery.js"></script>
<script>
    $(document).bind("mobileinit", function() {
        $.mobile.page.prototype.options.domCache = false;
    });
</script> <!-- Note your script before jqm -->
<script src="jquery-mobile.js"></script>

Solution 2

Sometimes you don't want to disable page cashing on a app level, in this case data-cache="false" should work, unfortunately it is not working as intended. But it can be forced like this:

$('div').on('pagehide', function(event, ui){
  var page = $(event.target);

  if(page.attr('data-cache') == 'false'){
    page.remove();
  };
});

This part of code will remove page after it is hidden.

Here's a live jsFiddle example: http://jsfiddle.net/Gajotres/wgLzu/

Upvotes: 2

Related Questions