Glossary
Fingerprinting
When serving a static file, Rails generates a fingerprint of the file contents. When the website links that static file, Rails automatically replaces the filename with the fingerprinted version. The line
<%= stylesheet_link_tag 'main.css' %>
is turned into something similar to
<link rel="stylesheet" href="/assets/application-58efc3ca.css" >
Whenever the file content changes, the fingerprint changes as well. This allows browsers to cache the file for a long time (in Rails, it is currently set to one year). Because whenever the file changes, the fingerprint is changed and the browser requests the new file (now with a different filename).
Precompilation
Precompilation turns source asset files (SASS, TS, CSS or any other) into files ready to be served
to the clients. This can include compilation, minification or uglification, depending on the
needs of the application. Additionally, the files are placed in
public/assets
to be delivered by the server.
Precompilation is usually not necessary in development mode, because the Rails application server can serve the files directly.
In contrast, in production, the precompilation is usually run during deployment. This ensures that the newest version of the files are served. To run the precompilation manually:
RAILS_ENV=production rails assets:precompile
Important: Do not run this command in development mode. It creates a marker file named
.manifest.json
indicating to the
application that it can serve the compiled files. Any changes you do to your assets will no longer be
reflected. If your assets are no longer updating in development mode, remove the file
public/assets/.manifest.json
.