Asset pipeline · precompile · Local

Optimize Rails Images — Before the Asset Pipeline Fingerprints Them

Compress the images in app/assets/images and public/ before you precompile. Sprockets and Propshaft fingerprint your files; neither re-encodes them.

Quick answer

Rails' asset pipeline copies images from app/assets into public/assets with a fingerprint in the filename, and files in public/ are served as they are. Neither step shrinks an image. Compress app/assets/images and public/ with TinyPixels before you run assets:precompile.

How to compress images before assets:precompile

1

Download and open TinyPixels

Free to install on Mac or Windows — no account needed to start.

2

Resize oversized view art

Marketing and landing-page images are often saved at several times their displayed size.

3

Compress the folders

Drop them into TinyPixels. Convert large hero images to WebP if you update the image_tag calls.

4

Commit and precompile

The pipeline fingerprints the smaller files exactly as before.

What the Rails asset pipeline does with images

The pipeline's job is naming and delivery. Sprockets, and Propshaft in newer Rails versions, give each file a fingerprint so it can be cached forever, and copy it into public/assets when you precompile. Sprockets can also minify CSS and JavaScript; neither pipeline compresses images.

That leaves image size entirely in your hands. Views call image_tag or asset_path with a logical name, and the pipeline resolves it to the fingerprinted file. Whatever you put in app/assets/images is what ships.

Rails apps often have a second image source: Active Storage uploads, where variants are generated at runtime through image_processing with libvips or ImageMagick. That is a server-side concern. The files you commit to the repository, such as logos, illustrations and marketing art, are the ones a pre-commit pass can shrink.

app/assets and public/

Both folders covered; the pipeline treats them differently, the file size matters in both.

Sprockets or Propshaft

Either pipeline fingerprints what it is given. The pass happens before both.

No gem to maintain

No image_optim gem, no system binaries to install on the deploy host.

Format conversion

Convert hero art to WebP and update your image_tag references.

How Rails treats an image

LocationWhat happensYour move
app/assets/images (Sprockets)Fingerprinted and copied to public/assets on precompile. No re-encoding.Compress before commit
app/assets/images (Propshaft)Fingerprinted and served. Intentionally simpler, no image processing.Compress before commit
public/Served as-is by the web server.Compress before commit
Active Storage uploadsCreated at runtime; variants come from image_processing.Handle in application code
CSS and JS pipeline stepsCan minify stylesheets and scripts, not images.Do not expect image savings

Which pipeline and defaults you have depends on your Rails version. Check your Gemfile to see whether you're on Sprockets or Propshaft.

Common mistakes with Rails images

Expecting precompile to compress images

It fingerprints and copies. The compression step has to happen before it, in the files you commit.

Compressing public/assets

That folder is generated by precompile and gets overwritten. Work on app/assets/images instead.

Confusing Active Storage variants with static art

Variants are made per upload at runtime. Logos and marketing images in app/assets are separate files that never go through them.

Renaming a file without updating the helper call

If image_tag points at the old name, the app raises an asset-not-found error in views. Search your views and stylesheets after converting.

Frequently asked questions

Does the Rails asset pipeline compress images?

No. It fingerprints and copies them. Sprockets can minify CSS and JavaScript, but images are not re-encoded.

Is there a difference between Sprockets and Propshaft for images?

Both fingerprint and serve images without re-encoding them. Propshaft is a simpler pipeline in newer Rails versions, so the advice to compress beforehand is identical.

What about Active Storage images?

Uploads are processed at runtime, typically with image_processing, which is outside what a pre-commit pass can reach. TinyPixels handles the static images you ship in the repo.

Which folder should I compress in a Rails app?

app/assets/images and public/. Not public/assets, which precompile regenerates.

Can I batch compress my whole Rails images folder at once?

Yes. Drop the folder into TinyPixels and every image compresses in one local pass.

Lighten your Rails deploys

Free to start. No credit card, no account, no cloud. See Pro pricing →