开发者

jQuery clear cache on logout

开发者 https://www.devze.com 2023-03-20 01:44 出处:网络
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 pag

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开发者_StackOverflow中文版 the cache?

I'm using jQuery Mobile 1.0b2pre.


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('/');
});


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


To avoid changing the URL of all your pages, you could send an ETag header with each response in the session based on the session ID. If you also include Cache-Control:must-revalidate, this should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消