When work with rails scss→ our main goal to load compiled scss to css in builds files.
- what is the mainfest.js inside assets
The manifest.js file in Rails assets is a special configuration file that declares all the assets (JavaScript, CSS, images) that should be included in your application. Let me explain what each line in your manifest.js does:
-
//= link_tree ../images- This links all images from the
app/assets/imagesdirectory
- This links all images from the
-
//= link_tree ../../javascript .js- This links all JavaScript files from the
app/javascriptdirectory - The
.jsextension specifies that only JavaScript files should be included
- This links all JavaScript files from the
-
//= link_tree ../../../vendor/javascript .js- This links all JavaScript files from the
vendor/javascriptdirectory - These are typically third-party JavaScript libraries
- This links all JavaScript files from the
-
//= link_tree ../builds- This links all files from the
app/assets/buildsdirectory - This is commonly used for files generated by build tools (like webpack or esbuild)
- This links all files from the
-
//= link application.css- This specifically links the application.css file
- This is your main stylesheet file
This manifest file is used by the Asset Pipeline in Rails to determine which assets should be compiled and made available to your application. The Asset Pipeline will use this manifest to:
- Combine multiple files into one
- Compress and minify assets
- Add fingerprints to filenames for cache busting
- Serve assets efficiently in production
This is a standard setup for a modern Rails application using importmaps or other JavaScript bundling approaches.
Question:-
okay so using these configs the staic fringerprints files are generated to public assets
Yes, that’s correct! The manifest.js configuration leads to the generation of fingerprinted static assets in the public/assets directory. Here’s how it works:
- When you run
rails assets:precompile(which happens automatically in production), Rails:- Reads this manifest.js file
- Processes all the specified assets
- Generates fingerprinted versions in
public/assets
For example:
- An image
logo.pngmight becomelogo-f761237864.png - Your
application.cssmight becomeapplication-a2d4c5e6f7.css - JavaScript files will be compiled to something like
application-b3d5f7g8h9.js
The fingerprint (that random string in the filename) is a hash based on the file’s content. This is crucial for:
- Cache busting: When you modify an asset, its fingerprint changes, forcing browsers to download the new version
- Better caching: Since fingerprinted files are content-based, unchanged files keep the same name and stay cached
You can find these generated assets in:
/Users/sandipparida/work/spacelozen/lozen/public/assets/
This is how Rails ensures efficient asset serving in production while maintaining proper cache control.
Question:- but now in public assets there no assets i delted it but still the css are working how?
In development mode, Rails doesn’t require precompiled assets in the public/assets directory. Here’s why your CSS is still working:
-
In development environment, Rails serves assets directly from your
app/assets,app/javascript, and other source directories specified in the manifest.js -
The Asset Pipeline processes these files on-the-fly when:
- You make a request to your application
- The assets are compiled in memory
- They are served directly without writing to
public/assets
This is different from production where:
- Assets must be precompiled (
rails assets:precompile) - Static files must exist in
public/assets - Serving is done through the web server (nginx/apache) directly from
public/assets
To verify this, you can:
- Check your browser’s developer tools
- Look at the Network tab
- Find your CSS file request
- In development, you’ll see it served from
/assets/application.cssbut it’s actually coming from your source files, notpublic/assets
- In development, you’ll see it served from
This on-the-fly compilation in development makes it easier to work on your assets without having to precompile them every time you make a change.
Question in my dev env its requested to this :-http://localhost:3000/assets/application-d3e7bd71.css
, but in my project there no file named this
This is normal behavior in Rails development! Let me explain what’s happening:
-
The
application-d3e7bd71.cssis a fingerprinted filename that Rails generates dynamically in development. The-d3e7bd71part is a hash based on your CSS content. -
In development, Rails uses Sprockets (Asset Pipeline) to:
- Compile your CSS files on-the-fly
- Generate a virtual fingerprinted filename
- Serve the content through the
/assetsendpoint - Cache the compiled assets in memory
Your actual source files are in:
app/assets/stylesheets/application.css(or .scss)- Any other CSS files imported by your application.css
The fingerprinted URL is generated for cache-busting purposes, but in development:
- The file doesn’t physically exist on disk
- It’s served virtually by the Asset Pipeline
- The fingerprint changes when you modify your CSS
This is why you won’t find application-d3e7bd71.css in your project files, but your styles still work perfectly. If you want to see the actual source files that make up this compiled CSS, look in your app/assets/stylesheets directory.
Question:- but i am using propshaft
Yes, I notice you’re using Propshaft instead of Sprockets (the traditional Asset Pipeline). This explains the asset behavior we discussed earlier!
Propshaft is Rails’ modern asset pipeline that:
- Is lighter and faster than Sprockets
- Uses a simpler fingerprinting approach
- Works differently in development mode
With Propshaft:
- In development, it serves assets through Rails’ built-in server
- It still generates fingerprinted URLs (like
application-d3e7bd71.css) - But instead of compiling on-the-fly like Sprockets, it watches your assets for changes and updates them when needed
- The fingerprinted assets are kept in memory during development
This is why you see the fingerprinted URL (application-d3e7bd71.css) even though the file doesn’t exist on disk. Propshaft handles this differently from Sprockets, but the end result is similar - your assets are served efficiently in development without needing to manually precompile them.
In production, Propshaft will still generate physical fingerprinted files in public/assets when you run rails assets:precompile.