Home  >  Q&A  >  body text

ruby - rails 怎么清除浏览器的资源缓存?

一rails项目 现在有一问题:我修改了这个swf文件的参数后。页面加载的是上一个swf文件,例如:
1:有一个 attack.swf 文件要在这个页面中预览
2:发现attack.swf中一些元素的位置x,y不正确。
3:于是我在页面中修改了这些参数,用程序打包后再次生成attack.swf
4:然后刷新见面。
这个时候我发现我修改的参数并没有起作用,国为浏览器加载的是上一个swf文件没有加载我新打包的文件。我清除浏览器的缓存后刷新就可以看到我新修改的swf文件。
问:有没有什么方法在rails 中清除这些缓存呢?

PHPzPHPz2712 days ago642

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-21 10:57:55

    This actually has nothing to do with RAILS.
    Mainly the configuration of the website's resource server, which may be Apache/Nginx or the ones that come with ruby.
    You can imitate the way ruby ​​handles resource files. If the swf changes, change the name to avoid caching problems

    reply
    0
  • 高洛峰

    高洛峰2017-04-21 10:57:55

    Go check out Rails’ Asset Pipeline http://guides.rubyonrails.org/asset_p...

    Rails will add a parameter to your static resources, attack.swf?t=12
    Once it is detected that your static resources have changed, this parameter will change to attack.swf?t=13

    You can also refer to this method. The principle is that the browser thinks that your resource is new and will reload it.
    Otherwise, it will always be 304 Not Modified, and the browser cache will be too troublesome.

    reply
    0
  • Cancelreply