Ryan
Ryan

Reputation: 65

Heroku - CSS not loading on a single page but everywhere else

Sorry in advance, I know there are topics on this subject, but this is maddening! I wouldn't be as frustrated if this problem wasn't limited to just the index. The CSS loads fine all on the pages of my app except the post/index page. I should note it runs perfectly locally and I've been banging my head against this since this morning so I may have overlooked something banal and apologize in advance.

Gem file

gem 'rails_12factor', group: :production
gem 'pg', group: :production

Production.rb

config.cache_classes = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true

Running the following was unsuccessful:

RAILS_ENV=production bundle exec rake assets:precompile
bundle exec rake assets:precompile

Specifying while assets to precompile in production.rb was unsuccessful

config.assets.precompile += %w( public.css public.js )   
config.assets.precompile += %w( assets/stylesheets )

Also tried changing the extensions from .css to .scss and adding a new custom.scssand linking to it without success.

Link to my app and the page in question: https://clickbait22.herokuapp.com/

Link to its Github repository: https://github.com/4thking/clickbait

Upvotes: 1

Views: 255

Answers (1)

Tim
Tim

Reputation: 1376

Try running...

heroku run bundle exec rake assets:precompile
heroku open

In production, you must run rake assets:precompile to serve up anything in your app/assets folder. In development mode, Rails constantly checks for updates to the files and serves them each one separately.

It is nice when you're developing, but is quite slow in production. So, to speed things up, Rails has you run a single, longer task that shrinks and combines a bunch of files in app/assets, speeding up page loading times and reducing server load.

Hope this helps you out!

UPDATE:

Whilst you said that you have tried doing the following, I want to include it for clarity regardless. Quite often it is important to precompile your assets before you push to Heroku. Inside the terminal this process would look similar to this...

rake assets:precompile
git commit -m 'Assets precompiled'
git push heroku master

Upvotes: 1

Related Questions