Updating assets without restarting rails server
Asked Answered
R

2

6

So the question basically boild down to this:

How do you efficiently handle changing assets in a production rails environment without the need to restart the server?

The problem we're experiencing is, we have to restart the Thin server that runs the app in order for the updated javascript files to be served.

Some background:

Right now we're generating data from a couple of long running tasks into javascript files once an hour so we can use it in our Rails app.
To be clear, we update/overwrite existing files, not adding new ones.

After generation we run these commands in order to re-precompile all the assets.

bundle exec rake assets:precompile
bundle exec rake rails_group=assets assets:clean RAILS_ENV=production

Still after clearing the browser cache and reloading the page we're being served the old assets.

Have you guys made any similar experiences; what did you do to work around it?

PS. Happy holidays to you all!

Resolvable answered 21/12, 2012 at 13:44 Comment(4)
Perform a touch tmp/restart.txt on the server shell, on your application folder.Snowstorm
touching tmp/restart only works for passenger, not thinCarolinacaroline
Are your assets fingerprinted or do you use a timestamp in the querystring of your assets URL ? ( guides.rubyonrails.org/… ) If you use neither of these techniques then it seems logical you are served stale assets. You might maybe turn on compilation on the fly and do not run the precompilation every hour, just do the cleaningCarolinacaroline
@systho, You are actually making a very valid point there, i actually haven't even considered disabling the asset pipeline. That might solve the problem.Resolvable
R
2

So, what we ended up doing is basically letting rails also serve static assets by setting

config.serve_static_assets = true in config/environments/production.rb

and just putting the frequently changing javascript data files into a directory structure under public/. This works grate since it also separates assets and data into different locations.

Resolvable answered 22/12, 2012 at 10:40 Comment(0)
B
0

According to the Rails guide:

6 How Caching Works Sprockets uses the default Rails cache store to cache assets in development and production.

Rails is going to cache your assets unless you tell it to not cache them. The whole point of the asset pipeline is to serve assets as quickly as possible by encouraging browsers and servers and the rails servers themselves to cache the assets.

If your use case involves redoing assets very often, maybe the asset pipeline isn't for you.

Byproduct answered 21/12, 2012 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.