Skip to content

Instantly share code, notes, and snippets.

@andremedeiros
Created November 10, 2010 13:52
Show Gist options
  • Save andremedeiros/670865 to your computer and use it in GitHub Desktop.
Save andremedeiros/670865 to your computer and use it in GitHub Desktop.
(function ( jQuery ) {
$( 'body' ).delegate( ".ui-page", "pagebeforeshow", function( event, opts ) {
var $page = $(event.target),
reloadPage = false,
cacheStrategy = $page.data('cache'),
pageInstance = $page.data('page'),
invalidateCache = pageInstance.dirtyCache;
// Check if page never gets cached
if ( cacheStrategy == 'never' ) {
reloadPage = true;
// Check if data-cache has a number.
} else if ( !isNaN( cacheStrategy ) ) {
var currentTime = +new Date;
if ( invalidateCache && currentTime > invalidateCache )
reloadPage = true;
else if( !invalidateCache )
pageInstance.dirtyCache = (cacheStrategy * 1000) + currentTime;
}
if ( reloadPage ) {
var url = $page.attr( 'id' ) || '/';
$page.page( 'destroy' );
$.ajax({
url: url,
async: false,
cache: false,
context: $page,
success: function(data) {
this.html($(data).html()).page();
}
});
}
return true;
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment