skip to content

Under Propshaft, why do CSS edits stop appearing in development after a local bin/rails assets:precompile, and how do assets:clobber and assets:clean differ?

level: middleimportance: should knowfreq 33%

answer

  1. manifest flips the resolver to static
  2. the precompile task warns in development
  3. clobber deletes public/assets entirely
  4. clean keeps 2 newest per asset
  5. anything under an hour old survives

basics

~20 s

Precompiling writes public/assets/.manifest.json, and while that file exists Propshaft resolves through it instead of the source files, so edits are ignored. assets:clobber deletes the whole output directory; assets:clean only prunes old digested versions, keeping the two newest of each asset by default plus anything under an hour old.

solid answer

~40 s

`bin/rails assets:precompile` writes `public/assets/.manifest.json` and the digested copies. Propshaft's assembly picks its resolver once per process: with a manifest it uses the **static resolver**, which maps logical paths to the stamped names in that file, so the helpers keep emitting the old digests and your edits never show. The task even prints a warning when run in development. Fix it with `bin/rails assets:clobber`, which removes `config.assets.output_path` (`public/assets`) including the manifest, then restart the server. `bin/rails assets:clean` is the opposite tool: it keeps the output directory and deletes only **stale digested versions**, keeping for each asset the 2 most recently written versions (`assets:clean[5]` changes the count) plus anything written in the last hour, so pages still open in browsers find their files after a deploy.

code

bash · 7 lines
bash
bin/rails assets:precompile   # writes public/assets/.manifest.json
# ...edits are now ignored in development...
bin/rails assets:clobber      # removes public/assets and the manifest
bin/rails server              # restart: dynamic resolver again

bin/rails assets:clean        # keep the 2 newest versions per asset
bin/rails "assets:clean[5]"   # keep the 5 newest versions per asset

go deeper

for a junior

Recall that a local precompile freezes assets in development, and that bin/rails assets:clobber plus a restart undoes it.

for a middle

Explain the static versus dynamic resolver switch on .manifest.json, and what clean keeps: the two newest versions per asset and anything under an hour old.

for a senior

Show when each task belongs in a deploy: clean on a persistent asset directory, clobber only for a fresh build or a broken dev machine.

for a principal

Talk about asset retention as a policy across releases: how long old digests must stay reachable for cached pages and long-lived tabs.

## The symptom A developer runs `bin/rails assets:precompile` on a laptop to check what production will get. From then on, changes to `app/assets/stylesheets/*.css` never reach the browser, even after reloading. The task warned them at the time: *"You are precompiling assets in development. Rails will not serve any changed assets until you delete public/assets/.manifest.json"*. ## Why: the resolver follows the manifest **Propshaft** has two ways to turn a logical path such as `application.css` into a URL: | Resolver | Chosen when | What it reads | |---|---|---| | `Propshaft::Resolver::Dynamic` | no manifest file exists | the load path, digesting files as they are now | | `Propshaft::Resolver::Static` | `config.assets.manifest_path` exists | the frozen map in `.manifest.json` | `Propshaft::Assembly#resolver` checks for the manifest the first time a helper needs it and memoises the choice for the life of the process. After a precompile, `stylesheet_link_tag` keeps returning the digests recorded in the manifest, which point at the copies in `public/assets` — copies made before your edit. The selection does not look at `RAILS_ENV`: a manifest in development switches development to static resolution just as it does in production. ## assets:clobber — start over `bin/rails assets:clobber` calls `Propshaft::Processor#clobber`, which deletes `config.assets.output_path` recursively — by default `public/assets`, the digested files **and** `.manifest.json`. Because the resolver is chosen once per process, restart the server afterwards so it starts with the dynamic resolver again. Use clobber: - after an accidental local precompile; - in a build when you want output generated from nothing; - never on a live server whose open pages still reference the old digests. ## assets:clean — prune, do not wipe `bin/rails assets:clean` (optionally `assets:clean[count]`) calls `Propshaft::OutputPath#clean(count, 1.hour)`. It groups every file in the output directory by logical path and, for each group: 1. Sorts the versions newest first by modification time. 2. Keeps versions while either holds: fewer than `count` have been kept (default **2**), or the file is **younger than one hour**. 3. Deletes the first version that fails both conditions and every older one after it. A fresh precompile writes each changed asset's new version last, so the version the current sources produce is normally the newest and is kept; the code also tries to spare the entry the current manifest names. The point is deploys that reuse `public/assets` between releases — a persistent volume, or an asset host synced from one. A browser that loaded yesterday's HTML still asks for yesterday's `application-<old digest>.css`; keeping a couple of previous versions lets that request succeed while the directory stops growing forever. ## Incremental precompile `assets:precompile` rewrites the manifest every time, but it only writes a digested file if that file does not exist yet. Re-running it after a small change copies just the assets whose digest changed. It never deletes anything — that is `assets:clean`'s job. ## The commands side by side | Command | Deletes | Keeps | Typical use | |---|---|---|---| | `assets:precompile` | nothing | everything already there | build step | | `assets:clean[count]` | stale digested versions | `count` newest per asset + last hour | between deploys on a shared output dir | | `assets:clobber` | the whole output path and manifest | nothing | reset a dev machine or a build | | `assets:reveal` | nothing | — | list logical paths on the load path | ## Practical habits - Add `public/assets` to `.gitignore` (a new app's does) so a local precompile never reaches the repository. - If you need to watch compiled CSS change during development, run `bin/dev`, which keeps the CSS or JS builders in watch mode while the dynamic resolver serves the results. - After clobbering, check that `bin/rails assets:reveal` lists what you expect before blaming the browser cache. ## Where these tasks sit in a build In a container build, `assets:precompile` runs once while the image is built and the result ships inside the image; each release starts from an empty `public/assets`, so neither `clean` nor `clobber` is needed there, and old digests disappear with the old container. Pages already open in a browser may then ask for a digest the new image does not have, which is why some teams keep previous assets reachable elsewhere — a deployment concern, not a Propshaft one. `assets:clean` earns its place when the output directory survives between releases: - a server that pulls new code into the same checkout and precompiles in place; - a shared volume or object store that several releases write into; - an asset host that receives each release's `public/assets` on top of the last. There, running `assets:clean` after `assets:precompile` caps growth without breaking requests for the version that was live a minute ago. Running `assets:clobber` in the same spot would delete the files the previous release's pages are still asking for.

  • Why is assets:clean safer than assets:clobber on a server that keeps public/assets between releases?
    Pages rendered before the deploy still reference the previous digests. `assets:clean` deletes only versions beyond the `count` most recent per asset (2 by default) and spares anything written in the last hour, so those requests keep working. `assets:clobber` removes every file and the manifest at once.
  • Does deleting only public/assets/.manifest.json fix the development problem?
    Yes, once the server restarts: with no manifest, Propshaft's assembly picks the dynamic resolver, which digests the current source files. The stale digested copies stay on disk but are no longer referenced; `assets:clobber` removes them as well and is the cleaner fix.

  • Propshaft always resolves assets dynamically in development, whatever is in public/assets
  • assets:clobber only deletes old digest versions and keeps the current ones
  • assets:clean wipes public/assets so the next precompile starts from scratch
  • A hard refresh in the browser fixes the stale CSS after a local precompile
  • The static resolver is selected because RAILS_ENV is production