简体   繁体   English

Rails 3.1 .css.less缓存错误

[英]Rails 3.1 .css.less caching error

I am quite new with Rails and I am having some irritating problems with caching of css files. 我对Rails很新,我对缓存css文件有一些恼人的问题。

I have a .css.less file with imports inside it. 我有一个带有导入的.css.less文件。 It's the only stylesheet the app includes, so the other files get imported only once and by this unique stylesheet. 它是应用程序包含的唯一样式表,因此其他文件只能导入一次并由此唯一样式表导入。 One of those imported .css.less stylesheets seems to be cached somewhere, because does not change in the browser when I change it's source. 其中一个导入的.css.less样式表似乎在某处缓存,因为当我更改源代码时,浏览器中的更改不会发生变化。

I can only see the changes I made if I change something in the root stylesheet. 如果我在根样式表中更改了某些内容,我只能看到我所做的更改。

I have the server in development mode, so the caching should be off. 我让服务器处于开发模式,因此缓存应该关闭。 I have also used <%= stylesheet_include_tag "style", :cache => false %> 我还使用了<%= stylesheet_include_tag "style", :cache => false %>

I tried with Chrome and Firefox, with and without clearing their cache too. 我尝试使用Chrome和Firefox,无论是否清除缓存。 Always the same result, if I work only on that file the css the page receives when reloaded doesn't have the changes... 总是相同的结果,如果我只在该文件上工作,重新加载时页面收到的css没有更改...

I also stopped the server and rm everything in the tmp folder of the app. 我也停止了服务器并在应用程序的tmp文件夹中输入了所有内容。 No changes. 没有变化。

I am using Rails 3.1 with Ruby 1.9.3, with the less-bootstrap-rails gem. 我使用Rails 3.1和Ruby 1.9.3,使用less-bootstrap-rails gem。 Both the root stylesheet and the imported one have .css.less extension. 根样式表和导入的样式表都具有.css.less扩展名。

What am I missing? 我错过了什么?

Thank you! 谢谢!

I had this on Rails 4.0.8, infuriating. 我在Rails 4.0.8上有这个,真气。 The config changes mentioned above didn't help. 上面提到的配置更改没有帮助。 Here's what seems to have fixed it for me: 这似乎已经为我解决了这个问题:

  • Ensure NO FILES share a base name. 确保NO FILES共享基本名称。 For example, you have a reports.css.less and a reports.js.coffee? 例如,你有一个reports.css.less和一个reports.js.coffee吗? Doesn't matter if they're in the same directory or not. 如果它们在同一目录中则无关紧要。 Rename or delete one of them. 重命名或删除其中一个。 (I changed it to reports-styles.css.less). (我将其更改为reports-styles.css.less)。

  • Blow away your cache: rm -rf tmp/cache 吹掉你的缓存:rm -rf tmp / cache

  • Restart your Rails app. 重新启动您的Rails应用。

This appears to be a decent fix but, since I don't know what's actually going on, this could be totally false and it's just working by coincidence now. 这似乎是一个不错的修复,但是,因为我不知道实际发生了什么,这可能是完全错误的,现在只是巧合。 Sorry this answer isn't more rigorous! 对不起,这个答案并不严谨!

This is an area where I think the asset pipeline is broken, but I don't think there's a good fix. 这是一个我认为资产管道破裂的领域,但我认为没有一个好的解决方案。

If I remember correctly, to get changes in files you've included/required in your .css.less file, you need to change the .css.less file itself. 如果我没记错的话,要更改.css.less文件中包含/要求的文件,您需要更改.css.less文件本身。

I've just came across the exact same problem. 我刚刚遇到了同样的问题。

I found that if you rename your *.css.less file (the one with the imports inside) to *.less , then this weird cacheing problem gets resolved. 我发现如果你将*.css.less文件(里面有导入的文件)重命名为*.less ,那么这个奇怪的缓存问题就会得到解决。

Add this to your config/application.rb 将其添加到config / application.rb中

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

See more at: Ruby on Rails Guide: Asset Pipeline 有关详细信息,请参阅: Ruby on Rails指南:资产管道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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