删除缓存破坏在Rails生产

编程入门 行业动态 更新时间:2024-10-22 17:38:58
本文介绍了删除缓存破坏在Rails生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我以生产模式部署rails应用程序时,它会将日期时间字符串作为查询参数添加到所有静态资源网址的末尾。这是为了防止浏览器在重新部署应用程序后使用资产的旧版本。

When i deploy a rails application in production mode, it appends a date-time string as a query param to the end of all the static asset urls. This is to prevent browsers using old-out of date cahed copies of the assets after I redeploy the application.

有没有办法让栏杆使用旧的时间戳记,用于尚未更改的资产(而仅未更改的资产) )自上次部署以来。我想这样做,以防止用户重新下载那些没有改变的资产。

Is there a way to make rails use the old time stamps for the assets that have not changed (and only the ones that have not changed) since the last deployment. I want to do this to prevent users having to redownload those assets that have not changed.

推荐答案

我想你可以使用ENV [ 'RAILS_ASSET_ID']来更改缓存清除资产ID。不幸的是,这是所有资产。

I think you can use ENV['RAILS_ASSET_ID'] to alter the cache-busting asset ID. Unfortunately, this is for all assets.

但是如果没有设置,它将使用资产的源修改时间。如果自上次使用该文件以来,该文件未被修改,则不应该是一个问题。

But if it's not set, it uses the asset's source modification time. If that file hasn't been modified since the last time you used it, it shouldn't be a problem.

如果资产ID没有更改被改变了,可能是因为你的部署过程改变了修改时间,也许你可以看看调整。

If the asset ID is changing when they haven't been changed, it might be because of your deployment process altering the modification time and maybe you could look at tweaking that.

最后,你总是可以使用自己的自定义方法覆盖rails_asset_id 。

希望这有帮助。

更多推荐

删除缓存破坏在Rails生产

本文发布于:2023-10-16 05:43:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496666.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!