Slow assets compilation in development mode

后端 未结 3 1243
庸人自扰
庸人自扰 2020-12-29 11:43

I have a large rails app with hundreds of coffee script files.

Sometimes when I make a tiny change in a coffeescript file or I switch the branch the whole assets are

相关标签:
3条回答
  • 2020-12-29 12:11

    As others have pointed out, optimizing your assets is the #1 way to increase compilation speed (eliminate unnecessary files and pre-processors, import carefully, and use partials with caution). However, why are you turning config.assets.debug = false in development mode anyway? When it's false, sprockets will concatenate all your files together, and this can take quite a while if you have a large number of files.

    Instead, turn config.assets.debug = true, so assets are compiled and cached on the first request. Sprockets sets a Cache-Control HTTP header to reduce request overhead on subsequent requests. The browser gets a 304 (Not Modified) response. See the Rails Asset Pipeline documentation.

    0 讨论(0)
  • 2020-12-29 12:17

    Take a look at this middleware from the Discourse team. We've had great success with it in our rails 4 app -- took reload times down from a minute to 5 seconds in development.

    0 讨论(0)
  • 2020-12-29 12:28

    It's a sad truth, but you don't. There is not a clean way to solve this.

    However, there are some patterns you could follow to minimize your pain which if I understand correctly is having to wait a lot in development to see the changes.

    As said these have been seen here1 and here2.

    1. Take a look at item 2 from here1.
    2. Break your assets in many files. This will imply in fewer lines being processed when changes occur.
    3. Prefer css/js, they may not be as cool but require no compilation.
    4. Find something interesting to do while assets precompile. It may lower productivity but sure kills the pain.
    0 讨论(0)
提交回复
热议问题