Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between public/assets and app/assets in rails?

The Rails guide here says

"Any assets under public will be served as static files by the application or web server when config.serve_static_files is set to true. You should use app/assets for files that must undergo some pre-processing before they are served."

I'm using Rails 4.2.4. There is no public/assets folder. This leaves me wondering a few things:

  1. What is meant by "use app/assets for files that must undergo some pre-processing before they are served?"
  2. What is meant by pre-processing?
  3. How is a static asset different from other assets, and what are the performance benefits of using one pipeline over the other?
  4. Do I even need to worry about this if 4.2.4 has no public/assets folder?
like image 581
calyxofheld Avatar asked Nov 28 '15 23:11

calyxofheld


1 Answers

  1. Assets like javascript/css etc. need to be pre-processed - eg. minified, hashed for cache busting, passed through transpilers (like coffeescript) etc. Such assets should be kept in app/assets folder.
  2. I believe 1 already answers that.
  3. Passing each asset through transpilers/minifiers etc. as described in 1 during production will be very expensive and wasteful - because these assets don't change dynamically we can just do them once during pre-compilation and let static file server or cdn handle their delivery.
  4. When you precompile your assets in deployment, the compiled files will be generated into the public/assets folder.

I recommend reading this article, which explains asset pipeline in much detail.

like image 192
lorefnon Avatar answered Oct 04 '22 05:10

lorefnon