如何更新服务器缓存的CSS ?

时间:2022-05-30 07:28:24

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.

我刚刚启动了我的新rails站点,有一些CSS的东西需要修改,但是我认为CSS缓存阻止了我的修改。有办法清除缓存吗?我做错了什么?如果您需要更多的信息,请告诉我(我想不出任何代码可以帮助您),非常感谢。

1 个解决方案

#1


4  

If you're on Rails 3.1+, you can use the Asset Pipeline, it takes care of it for you.

如果您使用的是Rails 3.1+,您可以使用资产管道,它将为您处理它。

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.

如果您正在使用资产管道并仍然获得旧文件,这可能是因为您在部署时忘记重新编译资产。使用rake资产:clean & rake资产:在服务器上预编译,它会更新这些资产。

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 (*) does this, look:

还可以添加查询参数。这个网站(*)就是这样做的,看:

<link rel="stylesheet" type="text/css" 
      href="http://cdn.sstatic.net/*/all.css?v=bd28d262b63e">

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.

也就是说,当您部署新版本的样式表时,更新这个链接并增加版本号。但是,一些缓存代理仍然可能忽略这个参数。

#1


4  

If you're on Rails 3.1+, you can use the Asset Pipeline, it takes care of it for you.

如果您使用的是Rails 3.1+,您可以使用资产管道,它将为您处理它。

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.

如果您正在使用资产管道并仍然获得旧文件,这可能是因为您在部署时忘记重新编译资产。使用rake资产:clean & rake资产:在服务器上预编译,它会更新这些资产。

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 (*) does this, look:

还可以添加查询参数。这个网站(*)就是这样做的,看:

<link rel="stylesheet" type="text/css" 
      href="http://cdn.sstatic.net/*/all.css?v=bd28d262b63e">

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.

也就是说,当您部署新版本的样式表时,更新这个链接并增加版本号。但是,一些缓存代理仍然可能忽略这个参数。