最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery clear cache on logout - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Jul 14, 2011 at 10:51 Reporter 3,9485 gold badges35 silver badges49 bronze badges asked Jul 14, 2011 at 10:47 webjaywebjay 5,4989 gold badges47 silver badges64 bronze badges 2
  • Update: Server side Cache-Control etc wont work. We need JavaScript to do this. – webjay Commented Jul 14, 2011 at 12:05
  • because jQuery loads every page into the DOM and after that doesn't even query the server, unless you tell it to do so manually. – webjay Commented Jul 14, 2011 at 21:29
Add a ment  | 

3 Answers 3

Reset to default 6

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)

  1. 暂无评论