No way to get this to work on Heroku #486

alper opened this Issue Mar 6, 2014 · 12 comments


None yet
10 participants

alper commented Mar 6, 2014

Searching around the web there doesn't seem a straight forward way to get this to work on heroku.

I figured that putting everything on S3 as is the heroku recommended way for files would be the way to go. Then I read this:
which is all fine but after having done that it doesn't say what the result is. Do I run collectstatic, compress, both? Do I do it locally or do I let the heroku push hook do it for me? Or do I in fact disable the heroku collectstatic because I don't have lessc &co in the heroku environment anyway.

So at the least this would be a documentation bug for this page:

In principle this should work on heroku as well if you generate everything offline and check them into your version control, right?

There are these articles about setting up node and less in the heroku environment but they seem a bit excessive and don't in fact work:

Am I missing anything here? After spending half a day on this yesterday I'm giving up (the clear alternative is compiling everything locally using the standard front end tools).

syphar commented Mar 6, 2014

Not a bug ;)

But there were many questions ;)

  • in most load-scenarios I would use dj-static (as seen in the heroku docs) or whitenoise for serving static files on heroku.
  • if everything is configured fine, heroku runs collectstatic for you when you push your code
  • if you want to add offline-compression, you can add a post_compile script (see here) that runs compress for you
  • don't offline-compress locally, let heroku do this for you.
  • for installing lessc on heroku is another task, I would have to google and try, too .. But your first link looks promising (at least the post_compile script).

alper commented Mar 6, 2014

In the section linked above under "Using staticfiles" still no idea why you need to make your own storage subclass or what you need to do after you've done it.

I tried installing lessc on heroku but if the post_compile script given doesn't work directly, this is extremely tedious to debug and frankly it doesn't sound like a good idea to create a container with everything and the kitchen sink.

Amazed at how hard this is still, but if anybody tells me what is happening here:
I'll be happy to add a documentation patch.

I created a fork of django-skel that supports django-compressor, scss compilation, bower, and bunch of other stuff (and have it running on heroku). Is anyone interested in seeing it?

alper commented Mar 19, 2014

I think people would definitely be interested in seeing stuff that works!

konklone referenced this issue in sunlightlabs/dryrub Apr 1, 2014


Make django-compressor optional #2

@therippa: I'd be interested in seeing that, too.

diox added the deployment label Sep 26, 2015

stcqu commented Oct 16, 2015

Compressor's Online mode doesn't work on Heroku because Whitenoise only checks the static folder when the app is loaded (see my comment on issue #680). To use compressor in production I think you need to use it in Offline mode and run python compress before the app loads using Heroku's post compile hook. Heroku will automatically run collect static for you so that isn't an issue. I found heroku-django-cookbook helpful. I'm using TypeScript on my Django/Heroku app so I also needed to install node etc. This is possible via the post compile hook, a custom pip package, or a custom build pack. I think the post compile hook is the easiest way.

Chronial commented Dec 8, 2015

As I had this problem in combination with sekizai, using offline compression wasn't really an option. But this problem is actually quite easily fixed be extending whitenoise, so here's my solution:

Maybe someone wants to add some tests and documentation to that and send a proper PR to whitenoise? :)

Note: If you still want pre-generation or heroku, you could start the server and send some requests in your post_build hook.

Whitenoise docs mention django-compressor at

cirosantilli referenced this issue in cirosantilli/free-books-django-raw Jun 21, 2016


The big issue dump #1

manikos commented Nov 7, 2016

OK. This worked for me brilliantly!
Inside my root local directory (aka repo) I created a directory bin/ and inside that a file named post_compile. Inside the post_compile file I copy-pasted these data.
I did git add --all, git commit -m 'testing post_receive hook in Heroku', git push heroku master.
After the auto-run of collectstatic command by Heroku, it did run python compress and it did create a directory which contains all of my files compressed in one file!

remote:      $ python collectstatic --noinput
remote:        1247 static files copied to '/app/staticfiles'.
remote: -----> Running post-compile hook
remote: -----> Compressing static files
remote:        Found 'compress' tags in:
remote:         /app/templates/base/base.html
remote:         /app/templates/info/areas.html
remote:         /app/templates/info/profile.html
remote:        Compressing... done
remote:        Compressed 1 block(s) from 3 template(s) for 1 context(s).

karyon commented Feb 25, 2017 edited

if you're seeing OfflineCompressionErrors, also check out #443 where people suggest more workarounds.


karyon commented Feb 26, 2017

in the case of #831, what worked is doing offline compression locally, and pushing the result including the manifest.json to heroku. no S3 there though.


karyon commented May 23, 2017

here is another config that works for the author: #855 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment