如何更新服务器缓存的 CSS?
我刚刚启动了我的新 Rails 网站,我需要更改一些 CSS 内容,但我认为 CSS 缓存使我的更改无法正常工作。有没有办法清除缓存?我做错了什么?如果您需要更多信息,请告诉我(我想不出任何可以帮助您的代码),非常感谢您。
I have just launched my new rails site and there are come CSS things that I need to change but i think that the CSS caching is keeping my changes from working. Is there a way to clear out the cache? What am i doing wrong? Let me know if you need more information (i couldn't think of any code that would help you) and thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Rails 3.1+,则可以使用 Asset Pipeline,它会处理这个问题为你。
如果您正在使用Asset Pipeline,但仍然得到旧文件,这可能是因为您在部署时忘记重新编译资产。使用 rake asset:clean && rake assets:precompile 在服务器上,它将更新资产。
如果您不使用 Asset Pipeline,那么您可以使用一些老技巧。例如,您可以重命名该文件。这肯定会让客户获得新版本。
您还可以添加查询参数。这个网站(stackoverflow)就是这样做的,看:
也就是说,当您部署新版本的样式表时,更新此链接并增加版本号。不过,某些缓存代理可能仍会忽略此参数。
If you're on Rails 3.1+, you can use the Asset Pipeline, it takes care of it for you.
If you are using Asset Pipeline and still get old files, that's likely because you forgot to recompile assets when deploying. Use
rake assets:clean && rake assets:precompile
on the server, it'll update the assets.If you are not using Asset Pipeline, then there are some old tricks you can use. For example, you can rename the file. That'll certainly make clients get the fresh version.
Also you could add a query parameter. This very site (stackoverflow) does this, look:
That is, when you deploy a new version of stylesheet, update this link and increment version number. Some caching proxies might still ignore this parameter, though.