After a user logs out, if they hit the back button, they can go back to the last page they were on before logging out.
The app I am working on will often be used on a public computer (library or computer lab, for example) and I'd like to prevent users from being able to see anything from previous user sessions.
I'm on Rails 3 and Devise, btw, although it seems that this issue would come up with any framework or login mechanism.
Is the solution to use headers/meta-tags to disable browser-caching? Anybody know of a gem or tutorial that addresses this issue?
Look forward to your advice.
Cookies also keep track of which site you're logged in to—which is why, if you clear your cookies, you'll need to log back in to all of your accounts. Clearing your cache doesn't affect any of this.
Here's how... When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache.
IMPORTANT: Be sure and close/quit the browser and restart it after clearing the cache and cookies.
Use the below code in application controller .. it works for me. Hope this will help you. Thank you!!
code
before_filter :set_cache_buster
def set_cache_buster
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
Being on Rails, you can easly setup everything placed in the public
folder with an aggressive cache, and cherry-pick what else can be safetly cached, like the public "about" page.
You should set Cache-Control: no-cache
to prevent the browser to cache HTML pages, XML, JSON containing sensitive informations (basically anything that is accessible only with a proper login) and set a more aggressive cache for static assets like css and images.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With