简体   繁体   中英

Rails: manually clear asset pipeline cache

I know that rails clears the asset pipeline cache by itself when files are modified, but I have a special scenario. I am feeding my application as an HTML response to an ajax request, cross domain using rack-cors to bypass CORS.

The problem is that every time the ajax request goes through on the person's browser, I get a new application.js file:

this is three requests..three separate application.js files 错误

If I could clear the asset pipeline cache before the request is initiated, I think I could avoid this issue. Anyway I can programmatically do that? I'm not sure if this would be done on the rails side or the remote-client side. I'm assuming some jquery on the client side to clear cache, but really looking for some additional perspective on this issue. I have tried

$(#myresultsdiv).empty() 

with no luck. Any help greatly appreciated!

I would turn off assets pipeline as you are not getting the benefits of it if its being regenerated for every request.

In your environment config:

  # Enable asset pipeline
  config.assets.digest = false

  config.assets.enabled = false

I didn't manage to clear the asset pipeline cache, but I disabled nonce usage by using an ajax prefilter:

$.ajaxPrefilter('script', function(options) {
options.cache = true;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM