Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku - Updated JavaScript and CSS Not Loading

Ruby version: 2.1.5 | Rails version: 4.1.1

It seems as though my JavaScript and CSS are not updating on Heroku; the cached assets are still being used. I've removed my assets and then precompiled them before pushing to Heroku. Here are the commands I use for these actions:

Removing: rake assets:clobber

Precompiling: rake assets:precompile

I've also added RAILS_ENV=production before these commands to make sure they were being applied to the production environment. After running these commands, I then push my changes up to Heroku. Since precompiling before pushing didn't seem to be working, I've tried removing my assets and precompiling again on Heroku directly:

Removing: heroku run rake assets:clobber

Precompiling: heroku run rake assets:precompile

I went into my public/assets folder on Heroku, and this is what I found:

application-0d6606badc40d6084a3782d50651c010.css
application-0d6606badc40d6084a3782d50651c010.css.gz
application-1f88efe0ffc5587eebd6ead885bf955e.js
application-1f88efe0ffc5587eebd6ead885bf955e.js.gz
application-2c65403ee39420c6b413486e7d954ee3.js
application-2c65403ee39420c6b413486e7d954ee3.js.gz
application-39a78b6323729b437725f30cbcffab4d.js
application-39a78b6323729b437725f30cbcffab4d.js.gz
application-3ce5b6684c1d0a23d08a436030fea4c7.js
application-3ce5b6684c1d0a23d08a436030fea4c7.js.gz
application-3f735ad30db75bbfd113371a14c6a3f6.js
application-3f735ad30db75bbfd113371a14c6a3f6.js.gz
application-52560adc9af4957551dad7717d8987ff.js
application-52560adc9af4957551dad7717d8987ff.js.gz
application-534cb930570eba09f1a83d6ef11166c4.js
application-534cb930570eba09f1a83d6ef11166c4.js.gz
application-5bb0fcb61a9adf08e283ad247ed7f102.js
application-5bb0fcb61a9adf08e283ad247ed7f102.js.gz
application-7bcbc33806a603b057b3d09429629c83.css
application-7bcbc33806a603b057b3d09429629c83.css.gz
application-7bd83de789450a3acb020ab8086935e9.css
application-7bd83de789450a3acb020ab8086935e9.css.gz
application-7eb789f2ca8a49db4ff7095d6a7042c9.css
application-7eb789f2ca8a49db4ff7095d6a7042c9.css.gz
application-86b28f1fc499b53f20766336a8a6bb2e.css
application-86b28f1fc499b53f20766336a8a6bb2e.css.gz
application-9dda55d67da5b91e578c1a59509d1fff.js
application-9dda55d67da5b91e578c1a59509d1fff.js.gz
application-b743afe07578e24612848090bb8f8989.js
application-b743afe07578e24612848090bb8f8989.js.gz
application-c614c86454dba513e5e57bf604a9febf.js
application-c614c86454dba513e5e57bf604a9febf.js.gz
application-eee374eeb97a96414374797e0c9fc79c.js
application-eee374eeb97a96414374797e0c9fc79c.js.gz
application-f5dd56cc83e5cbff6105ff7e685d06b2.js
application-f5dd56cc83e5cbff6105ff7e685d06b2.js.gz
application-f8b34c1363fd3d16bc986d5e5b2a7c32.js
application-f8b34c1363fd3d16bc986d5e5b2a7c32.js.gz
bootstrap
manifest-136cd5bd1fa34e1319ea7deb5f933b55.json
manifest-15b224a7001a7bbe038449878d61ae56.json
manifest-1d571fcaa1a29e0de44c84db004f855f.json
manifest-26a02612b9bb6a5cbddde3ba6a6e4c79.json
manifest-2b4afca7ab226f8cf64fa24d11dae039.json
manifest-33d5fb906f0d92f5704b80c31623b9b8.json
manifest-361c06dd69f189783b32790da32fc00d.json
manifest-3e69106386e77ec5b2ef3aea206559cc.json
manifest-6a4901fcc600bed74f94b78afaa60abf.json
manifest-6c912bacdd6db8ea13780aa82cd7cfd6.json
manifest-77805855a3831e1e631438d166242b87.json
manifest-7c5085b7f41e857c1f280a92c37fe4c5.json
manifest-8627268e6cf6557e31e1160093545734.json
manifest-901ca9c0755e35e84b309426fa248352.json
manifest-91fc08ea4efe016b0dafa903dac29665.json
manifest-aebb057a0936e1a9a87fb6540028beda.json
manifest-c562fae7154ab54eec0e038ef8c2f10e.json
manifest-d410fdad309c708ecc1f5465370d6fa5.json

Clearly, there are way too many files in that directory than there should be, but I can't seem to get rid of them. I've deleted the entire public/assets folder and ran a heroku run rake assets:clobber command, but the folder keeps getting recreated with all of those files automatically.

How can I clear this huge cache?

like image 685
Alexander Avatar asked Mar 08 '15 05:03

Alexander


1 Answers

I figured it out! Whenever I ran a git status command, it would list out all of those deleted files from my public/assets folder. I believe the issue occurred because my public/assets folder was not being tracked by Git. I did the following to resolve the issue:

git rm -r public/assets

This removed all of the precompiled assets from my git repo public/assets and staged them for commit. Previously, they weren't staged for commit.

RAILS_ENV=production rake assets:precompile

I ran this after in order to precompile my assets before pushing to Heroku. After running the previous command, my public/assets folder was deleted.

git add .

This staged all of the new, modified, and deleted files in my project for commit.

After this, I just committed and pushed to Heroku, and now Heroku only lists a few files in the public/assets folder! I also see the updated JavaScript and CSS on my website!

like image 132
Alexander Avatar answered Sep 22 '22 17:09

Alexander