Created
October 17, 2014 10:19
-
-
Save ebouchut/77391c3bb85b19729034 to your computer and use it in GitHub Desktop.
Add a cache buster in a Rails controller action only for XHR requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
def action_xyz | |
if request.xhr? | |
set_cache_buster | |
end | |
render json: {what: 'ever'} | |
end | |
private | |
# See: http://stackoverflow.com/a/748646/386517 | |
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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment