I have some JS files being loaded by a page inside an iframe. In Chrome, a refresh doesn't s开发者_如何学Pythoneem to force a reload of the JS files, which are being worked on and modified fairly regularly. If I browse directly to the JS files, refresh, it seems to fix the issue. I've tried the following fix found elsewhere on StackOverflow, but that didn't seem to do it. Any ideas? The app is developed on Rails - perhaps I could use a JS packaging solution?
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
Are you using the asset helper javascript_include_tag ? Cause if you are as long as the config has the following:
config.action_controller.perform_caching = false
Every JS you include with that helper will be appended with a timestamp avoiding cache.
Example:
<%= javascript_include_tag "prototype", "application", "effects" %>
With perform_caching = true it will generate:
<script type="text/javascript" src="/javascripts/prototype.js"></script>
<script type="text/javascript" src="/javascripts/application.js"></script>
<script type="text/javascript" src="/javascripts/effects.js"></script>
But with perform_caching = false it will generate:
<script type="text/javascript" src="/javascripts/prototype.js?1197321216"></script>
<script type="text/javascript" src="/javascripts/application.js?1197321216"></script>
<script type="text/javascript" src="/javascripts/effects.js?1197321216"></script>
I did not test this code it might need some adjustment, it's been a while since i touched rails. Good Luck!
Sources:
tutorial
reference
精彩评论