17

In rails 3.1, when you precompile the assets, rails create public/assets directory and add files there.

Do you version-control public/assets/*?

1
  • 1
    Do you feel like your question got answered? If so please accept, otherwise a comment on what you're missing would be helpful.
    – Travis
    Commented Oct 6, 2011 at 1:05

2 Answers 2

12

I use Capistrano to deploy. The last step is compiling the assets. Nothing like that gets checked into version control.

https://github.com/capistrano/capistrano/wiki/Documentation-v2.x

Checking in compiled assets, .gz files/etc, will just clutter up version control.

4
  • It takes a good 10 minutes for rake assets:precompile to run for me on my Amazon EC2 micro instance. So deploying takes at least 10 minutes. On my dev box, it's less than a minute. With that in mind, do you think it makes sense to version-control the compiled assets? Commented Jul 24, 2012 at 6:15
  • At the end of Railscast episode #341, Ryan Bates mentions an idea of compiling the assets on a local machine and then modifying the capistrano deploy task to rsync the files to the production server; i.e. NOT put them in version control. Sounds good. Commented Jul 24, 2012 at 8:13
  • 1
    A reminder: after you compile the assets, your development environment might choose to serve those directly instead of generating them as needed. A quick solution for me was to delete /public/assets after the above cap assets:precompile and rsync task completes. Commented Jul 24, 2012 at 8:26
  • So now we do it slightly differently. EC2 micros do take forever to compile. The CI server builds an archive of the app, precompiled assets, and gem sources and dumps it on S3. The instances now pull from S3 the latest code when rebooted which already has the assets. They never end up in source control. This might not be the best way, but it's how we're doing it now.
    – Travis
    Commented Jul 24, 2012 at 18:15
5

I was looking for an answer to this too. I found the official Rails Guide has some thoughts on this:

http://guides.rubyonrails.org/asset_pipeline.html#local-precompilation

Here's a quote of the relevant section (emphasis added):

There are several reasons why you might want to precompile your assets locally. Among them are:

  • You may not have write access to your production file system.
  • You may be deploying to more than one server, and want to avoid duplication of work.
  • You may be doing frequent deploys that do not include asset changes.

Local compilation allows you to commit the compiled files into source control, and deploy as normal.

There are three caveats:

  • You must not run the Capistrano deployment task that precompiles assets.
  • You must ensure any necessary compressors or minifiers are available on your development system.
  • You must change the following application configuration setting:

In config/environments/development.rb, place the following line:

config.assets.prefix = "/dev-assets"

The prefix change makes Sprockets use a different URL for serving assets in development mode, and pass all requests to Sprockets. The prefix is still set to /assets in the production environment. Without this change, the application would serve the precompiled assets from /assets in development, and you would not see any local changes until you compile assets again.

In practice, this will allow you to precompile locally, have those files in your working tree, and commit those files to source control when needed. Development mode will work as expected.

So, it looks like it might be a good idea to put precompiled assets into VCS on occasion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.