1

As in older versions of rails, in production, we used to precompile our assets first so that performance can be better while serving assets from public. But in rails 7, as default configuration says that you should use all your css , fonts, and custom js files from asset pipeline and ecternal js libraries using importmaps, then what is the precompilation process of rails 7 in production.

Alex
  • 16,409
  • 6
  • 40
  • 56
Muhammad Ans
  • 157
  • 8

1 Answers1

1

Nothing changed. Asset pipeline aka sprockets or propshaft are used in development to serve any local assets, including import-maps. When you make changes, assets are compiled on the fly and new assets are served when you refresh the page. This process takes time, memory, and cpu cycles - something you don't want to waste in production.

Solution is to compile everything ahead of time - precompile. Everything goes into public/assets directory. Then web server, like nginx, is configured to serve any requests to /assets/* from public/assets/*. This way assets are served fast and your app server doesn't need to care about them.

use all your css , fonts, and custom js files from asset pipeline

Before we had sprockets and webpacker, two asset piplines that did the same thing. Two asset urls /assets and /packs, two compilation processes, two public directories public/assets and public/packs.

In rails 7 everything hooks into sprockets. Any new build tools, like tailwindcss, can process assets and put them in app/assets/builds where sprockets can do what it did before - compile and serve in development, precompile for production.

Alex
  • 16,409
  • 6
  • 40
  • 56
  • That means we should serve our css, fonts and custom js files from asset pipeline aka sprockets as it was done before webpacker was introduced. Only if we want to load any external javascript library like jquery, then we should do that kind of stuff using importmaps. Am I right in my observation?? – Muhammad Ans Jul 17 '23 at 17:32
  • @MuhammadAns you can use importmaps for your local javascript files. i've linked my answer on how to do that in your previous question. – Alex Jul 17 '23 at 17:41