ulver
ulver

Reputation: 1541

how to prevent sprockets from caching a .erb file?

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 = <%= Kernel.rand %>;

evaluates it once and caches forever. How do you prevent certain files like this from being cached by sprockets?

Upvotes: 3

Views: 661

Answers (1)

mu is too short
mu is too short

Reputation: 434685

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.

Upvotes: 2

Related Questions