Why would you be using config.assets.prefix in rails?

3.4k views Asked by At

I'm trying to figure out, whether I should be using config.assets.prefixin my development environment or not.

When I'm using localhost, for development, are there any (dis-)advantages of doing this? When the local server itself isn't caching and is on another domain (production-domain vs localhost), I fail to see the disadvantages? Especially for hard-coding some paths in CSS and Javascript, which will then always return 404's on development..

I've been using config.assets.prefix = "/dev-assets" as pr. reccomendation of another developer, who isn't working with us anymore.

Is this a problem, that anyone else have thought about and taken a standpoint at?

1

There are 1 answers

0
kvarnsbacke On

The biggest reason of using config.assets.prefix, emerges from the use of local asset precompilation. There are multiple reasons of precompiling locally and storing in source control. From http://guides.rubyonrails.org/asset_pipeline.html#local-precompilation

  • 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.

But if you use this, you will get into trouble in development mode because rails will serve your precompiled assets found in /public/assets. Therefore, you often set config.assets.prefix = '/dev-assets' so you don't need to precompile every time you want to see effects of local changes in /app/assets.