-
Notifications
You must be signed in to change notification settings - Fork 24
Disable .erb caching in development #563
Comments
I still have no intention of supporting this. |
@josh, is it a design-driven decision or would it help if we'll provide a pull request? I'm just curious why you're not intended to support it, is there any reason for this. |
I understand where @josh is coming from here. Sprockets is intended to handle static files (and eventually be pre-compiled, shipped to CDN, etc). While offering a way to make those static files seem dynamic would certainly be helpful in your use case, I'm not sure that is a good thing for Sprockets overall. It could very well lead to people accidentally relying on that dynamic behavior, and be surprised when they deploy out to prod and things behave differently. Is there a way you can make this So, I'd recommend registering your own engine for your file so that you can run custom code that calls |
This still not an ideal work flow. The reason those Rails configs work is that Rails always rereads all the files everytime it boots. A more similar analogy would be compiling to byte then loading the app from the bytecode. Now you have to decide when you recompile. If every deploy you want to reread and reprocess every file, sprockets already works that way. You're builds will be really slow, but I guess you can make that trade off. The big performance win comes from reusing artifacts from previous deploys.
Yes. You really want your build to be deterministic. If you can run you build, and every time produces different results, you're going to have a bad time. This probably includes anytime you might think to call into ActiveRecord in your assets.
I've been tempted for a while to pull support for |
In our case the only Here's an example from our latest deploy (only top-level modules are included):
This gets consumed by a simple module loader that can then be called with:
I understand the desire for builds to be deterministic though, and caching is usually a good thing. I'll look into other ways to build the manifest outside of the asset pipeline. |
@rymohr I do the exact same thing. Heres a snippet from our ace requirejs loader
|
Thanks @josh. I'll give that a try. |
@josh is that possible to do the same by depending on file outside of the assets folder? We're precompiling some of our data from |
I think I've found a solution for my case. In the file that depends on some content outside of <%
([Rails.root.join('db/data').to_s] + Dir[Rails.root.join('db/data/**/*')]).sort.each do |f|
depend_on(f)
end
%> It works just fine in 2.11.0, didn't check in later versions yet. |
I think depend_on just requires the file to be in the rails root in 2.x.
|
This is really needed for something like js_assets which dumps the list of assets in a js erb file |
I successfully used |
great! @dekart thanks for the solution! I finally understood |
This solved my problem, Thanks! I had a routes_json.js.erb that is never changed, but depends on the changing routes.rb (I want routes to be available in the static js client views).
where |
This is a follow up to #486.
My original suggestion to add a
nocache
directive is too heavy-handed. Instead, I think simply not caching .erb assets in development is the proper way to go. Better yet, piggyback onconfig.cache_classes
orconfig.action_view.cache_template_loading
to decide if these assets are cached or not.Caching them in development makes them practically useless as mentioned by @PikachuEXE and @dekart.
In production these assets should always be cached and served separately by the asset host. If you need these to be dynamic in production just use a standard AC view to generate the javascript dynamically as @josh mentioned.
The text was updated successfully, but these errors were encountered: