Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets are compiled every time app starts #352

Closed
yivo opened this issue Jun 3, 2016 · 13 comments
Closed

Assets are compiled every time app starts #352

yivo opened this issue Jun 3, 2016 · 13 comments

Comments

@yivo
Copy link

yivo commented Jun 3, 2016

After update from sprockets 2.x assets now are compiled every time app starts in development environment. What is exactly compiled? Everything! Application assets and assets from all loaded Rails::Engine.

To reproduce:

  1. start app
  2. open index page
  3. wait until all assets are compiled
  4. page load
  5. if you reload page assets are not recompiled (as expected).

Rails 4.2.5
sprockets 3.6.0
sprockets-rails 3.0.4

@rafaelfranca
Copy link
Member

Correct. It is a know and desired behavior. It is compiled to check if all your assets used in assets helpers are in the precompile list. There is an option to opt out this behavior at the master branch if you want to disable this check.

@yivo
Copy link
Author

yivo commented Jun 3, 2016

Yes. It is good it can be disabled because for me first request takes about 70 seconds.
Are speaking about this?
Installed sprockets-rails from master gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master', require: 'sprockets/railtie' and set Rails.application.config.assets.check_precompiled_asset = true but first request still compiles all assets.

@yivo
Copy link
Author

yivo commented Jun 3, 2016

Option check_precompiled_asset will only prevent exception and doesn't affect compilation on first request.

raise Helper::AssetNotPrecompiled.new(path) if @check_precompiled_asset && !precompiled?(path)

@rafaelfranca
Copy link
Member

Yes, it does. The compilation is made when the precompiled? is called.

@rafaelfranca
Copy link
Member

You have to set that option to false to disable it. If it is not working in your application maybe it is being compiled somewhere else.

@yivo
Copy link
Author

yivo commented Jun 3, 2016

I made a mistake when set check_precompiled_asset to true. The correct value is false. Now all works as desired. Thank you.

@mipearson
Copy link

I would recommend adding something to the Rails upgrade guide regarding this - given the number of apps with significant asset compile times in the wild this could surprise a lot of people.

In our case, it caused significant test speed regressions in our parallel tests, as sixteen threads all tried to compile 50s worth of assets at the same time.

@tomca32
Copy link

tomca32 commented Dec 23, 2016

While I like this behavior, it should definitely be mentioned in the upgrade guide.

@henrik
Copy link

henrik commented Jun 16, 2017

We were bitten by this as well. I agree – a mention in the upgrade guide, or possibly outputting that it happens in the server output (e.g. "Checked precompiled assets (took 1234 seconds)") so it's easier to determine what's going on.

@rafaelfranca, would you be open to a PR with one or both of the above? I guess upgrade guide might be good if you don't want to release a new 4.2.x for this (we saw it on an upgrade to 4.2). Though if this issue also exists in master, maybe we could do the other thing too.

@rafaelfranca
Copy link
Member

It doesn't fit the upgrade guide since you can upgrade rails without upgrading sprockets. This is a configuration in sprockets-rails and it is documented in sprockets-rails and it is in the CHANGELOG of sprockets-rails.

Maybe we could improve the sprockets-rails documentation, or maybe explain it in the assets pipeline guide?

@henrik
Copy link

henrik commented Jun 20, 2017

I see your point. I'm not sure we would have found it in any of those places, but that's not to say it wouldn't help someone else.

How would you feel about something like "Checked precompiled assets (took 1234 seconds)" in the server output. But perhaps only showing it if takes longer than say 10 seconds, to keep down on noise for everyone else? I think that would have helped us catch it sooner.

@davidsbailey
Copy link

The performance benefits of disabling config.assets.check_precompiled_asset are not well documented, and are very difficult to discover without locating this github issue and reading the above discussion. @rafaelfranca , would you accept a pull request to document this more clearly? #441

@prdetective
Copy link

prdetective commented Aug 22, 2019

Recently upgraded to sprockets 3.x. App has huge amount of assets - images and stylesheets. They should be loaded only under special conditions. With caching disabled, first request after server boot takes around ~1.5 minutes.

I've spent couple of days trying to understand what's going on, until I finally found this answer: https://stackoverflow.com/questions/35683185/rails-sprocketsrailshelperassetnotprecompiled-in-development#51898048 and set

config.assets.check_precompiled_asset = false

Logging time-consuming operations would definetely have helped and would have saved a lot of time.

hartsick added a commit to codeforamerica/honeycrisp-gem that referenced this issue Jan 27, 2021
I was getting an exception when loading the styleguide documentation
after running `bin/rails s` in development because my assets weren't
precompiled, which is expected in development. Changing this
configuration

I'm not sure when this was introduced (below issue suggests 2016, so may
have appeared once we upgraded Rails/Sprockets) or if others are running into it.

More: rails/sprockets-rails#352
hartsick added a commit to codeforamerica/honeycrisp-gem that referenced this issue Feb 2, 2021
I was getting an exception when loading the styleguide documentation
after running `bin/rails s` in development because my assets weren't
precompiled, which is expected in development. Changing this
configuration

I'm not sure when this was introduced (below issue suggests 2016, so may
have appeared once we upgraded Rails/Sprockets) or if others are running into it.

More: rails/sprockets-rails#352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants