Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery clear cache on logout

When users logout from my mobile app, how can I make sure the cache is cleared?

What I'm thinking about is to redirect /logout to a specific page that clears the cache and redirects to the front page, but how do I clear everything from the cache?

I'm using jQuery Mobile 1.0b2pre.

like image 239
webjay Avatar asked Jul 14 '11 10:07

webjay


2 Answers

Here's how I solved it:

My /logout action where the users session is destroyed in the backend redirects to /exit which has an id attribute of exitPage. In my JavaScript I have asked jQuery Mobile to trigger when that page is about to be created. I then empty the DOM and redirects to the front page.

/exit:

<div data-role="page" id="exitPage"></div>

/my.js:

jQuery('#exitPage').live('pagebeforecreate', function(){
    jQuery(document).empty();
    window.location.replace('/');
});
like image 115
webjay Avatar answered Oct 06 '22 10:10

webjay


you can't clear the cache. but what you can do is identify the user based on his session id, and append that to the assets urls someimage.png?cachecontrol=blablalba next time it enters, he will have a new session id so he will get new files even if the old ones are still in the cache. the other solution will be to explicitly set the cache control header to no-cache. but you can't force his browser to clear it's cache

like image 33
TheBrain Avatar answered Oct 06 '22 09:10

TheBrain