0
0
Ruby on Railsframework~8 mins

Public and assets folders in Ruby on Rails - Performance & Optimization

Choose your learning style9 modes available
Performance: Public and assets folders
MEDIUM IMPACT
This concept affects page load speed by controlling how static files like images, stylesheets, and scripts are served to the browser.
Serving static images and stylesheets in a Rails app
Ruby on Rails
Use the assets folder with the Rails asset pipeline to fingerprint, compress, and cache static files before deployment.
Files are optimized and cached, reducing load size and speeding up repeat visits.
📈 Performance GainReduces file size by 30-70%, enables browser caching, and speeds up LCP.
Serving static images and stylesheets in a Rails app
Ruby on Rails
Place all images and CSS files directly in the public folder without fingerprinting or compression.
Files are served without caching benefits or compression, causing slower load times and larger downloads.
📉 Performance CostBlocks rendering longer due to uncompressed large files; no cache control increases repeated load times.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Unoptimized public folder files0 (static files)0High due to large file size[X] Bad
Optimized assets folder with fingerprinting0 (static files)0Low due to compression and caching[OK] Good
Rendering Pipeline
Static files from public or assets folders are requested by the browser, then served by the server or CDN. Optimized assets reduce time in network transfer and browser parsing.
Network Transfer
Style Calculation
Paint
⚠️ BottleneckNetwork Transfer due to file size and caching strategy
Core Web Vital Affected
LCP
This concept affects page load speed by controlling how static files like images, stylesheets, and scripts are served to the browser.
Optimization Tips
1Always use the Rails asset pipeline to fingerprint and compress assets before deployment.
2Serve static files with proper cache-control headers to enable browser caching.
3Avoid placing large uncompressed files directly in the public folder to reduce load times.
Performance Quiz - 3 Questions
Test your performance knowledge
Why is fingerprinting assets in Rails important for performance?
AIt reduces the number of files in the assets folder.
BIt automatically compresses files on the server.
CIt allows browsers to cache files effectively by changing filenames when content changes.
DIt moves files from public to assets folder.
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and inspect static file sizes and caching headers.
What to look for: Look for compressed file sizes (gzip or brotli), cache-control headers, and fast load times for assets.