gmoore
gmoore

Reputation: 5566

Why should I use the Asset Pipeline to serve images?

In the Ruby on Rails guide to the Asset Pipeline, it says

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

http://guides.rubyonrails.org/asset_pipeline.html

To me, this says that images should be kept in the public directory as they can be served statically by my web server and require no pre-processing.

Are there advantages to putting your images in assets/?

Upvotes: 13

Views: 462

Answers (2)

Krists
Krists

Reputation: 451

Asset precompile appends unique hash value to image filenames, which allows users to get latest version of it despite of cache or expire settings on the server. This is useful when you want to change images in website design.

You don't want to use /assets/images for images what are unlikely to change (like user uploads).

Upvotes: 10

Daniel Evans
Daniel Evans

Reputation: 6808

Because it would harm the versatility of the asset pipeline.

With images being served via the asset pipeline, if you change the asset pipeline (for instance, have it upload files to S3) you would have to then sync your images via some other task.

There may be other, deeper reasons, but that is what would give me pause.

EDIT: Side note: In production thanks to assets:precompile everything from /assets/ will be served from public.

Upvotes: 4

Related Questions