Sprockets gem caches .erb files even though the ruby code in those might evaluate differently on every compilation
For example: foo.js.erb
var foo = <%= 开发者_StackOverflowKernel.rand %>;
evaluates it once and caches forever. How do you prevent certain files like this from being cached by sprockets?
You could separate your JavaScript into libraries (.js.erb
or just .js
) and configuration data (such as your var foo
). Then leave all the library code in the hands of Sprocket and put your configuration into your normal ERB views (probably embedded in your layouts).
You could also serve the configuration data through a separate controller (/config.js
perhaps) if that fits your architecture better.
This approach avoids your whole problem by separating static libraries from non-static data. Also, this approach fits nicely with the Rails 3.1 asset pipeline where you're supposed to pre-compile everything before your production deployments.
精彩评论