从Rails资产管道清除缓存 [英] Clear the cache from the Rails asset pipeline

查看:168
本文介绍了从Rails资产管道清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Rails中开始一个新项目,看起来app.js清单文件正在用我引用的javascripts做一些有趣的事情 - 它是否将这些文件缓存为资产管道的一部分?

I'm starting a new project in Rails, and it looks like the application.js manifest file is doing something funny with the javascripts that I reference - does it cache those files as part of the asset pipeline?

以下是发生的事情。我将一个名为jquery.autoresize.js的javascript文件添加到vendor / assets / javascripts文件夹中,然后在application.js清单中引用该文件,如下所示:

Here's what happened. I added a javascript file named jquery.autoresize.js to the vendor/assets/javascripts folder, and then referenced the file in the application.js manifest like this:

//= require jquery.autoresize.js 

然后我开始了rails服务器。但在我的应用程序中导航后,我意识到我不小心添加了错误版本的jquery.autoresize.js文件。因此,我删除了该文件,然后将正确的版本添加到vendor / assets / javascripts文件夹中。但是,令我恐惧的是,当我重新加载页面时,它仍在加载旧的javascript文件。

Then I started up the rails server. But after navigating around in my app, I realized that I had accidentally added the wrong version of the jquery.autoresize.js file. So, I deleted that file and then added the correct version to the vendor/assets/javascripts folder. But, to my horror, when I reloaded the page, it is still loading the old javascript file.

我尝试清空浏览器缓存,然后退出并重新启动Rails服务器,但无济于事。我通过简单地重命名我的javascript文件并引用新名称一起破解了一个解决方案,这个工作正常。但必须有一个更好的解决方案。

I tried emptying my browser cache, then exiting and restarting the Rails server, but to no avail. I hacked a solution together by simply renaming my javascript file and referencing the new name, which worked fine. But there has got to be a better solution to this.

新资产管道是否以某种方式缓存您引用的文件?如果是这样,我该如何清除缓存?感谢您的帮助!

Does the new asset pipeline cache the files you reference somehow? If so, how can I clear that cache? Thanks for any help!

推荐答案

我假设我们正在谈论生产环境。

I'm assuming we're talking about the production environment.

当你在生产环境中更改任何javascripts或样式表时,你需要运行 rake assets:precompile ;此任务编译和压缩各种.js和.css文件,并创建由您的视图加载的application.js和application.css文件。

When you change any of your javascripts or stylesheets in the production environment, you need to run rake assets:precompile; this task compiles and compresses the various .js and .css files and creates the application.js and application.css files that is loaded by your views.

如果有可能,您使用旧时间戳的版本替换了 jquery.autoresize.js ,预编译步骤可能会跳过它,认为编译的版本是最新的-日期。您可以先运行 rake assets:clean 来避免这种情况,强制它重建 public / assets 目录中的所有内容。划伤。

It's possible that if you replaced jquery.autoresize.js with a version with an older timestamp, the precompile step might skip it, thinking the compiled version is up-to-date. You can avoid that by running rake assets:clean first, forcing it to rebuild everything in the public/assets directory from scratch.

这篇关于从Rails资产管道清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆