We recently moved to Heroku avec we decided to store our assets on Amazon S3 with a Cloudfront distribution.
I use Django Pipeline to compress / compile my assets but I didn’t manage to make it points to the correct version.
When I run the “collectstatic” management command, it works well:
Post-processed ‘css/compress_profile_school.css’ as ‘css/compress_profile_school.82973855aca5.css
Post-processed ‘css/compress_profile.css’ as ‘css/compress_profile.d120536e24f9.css
Post-processed ‘css/compress_document.css’ as ‘css/compress_document.864dd7603769.css
…
But when I run the app, it didn’t point to the correct version (it uses the one with no hash).
The application is running here: http://dev.unishared.com/
It seems that the Django bundled staticfiles app can’t point to the correct version too.
Each time I push new assets version, I have to invalidate my Cloudfront distribution which takes time..
Thanks for your help.
Thanks to cyberdelia I managed to make it works.
First, the “CachedFilesStorage” only put hashname in the filenames if your DEBUG settings is turned off (= False).
It runs well on my production server.
From here, the “collectstatic” command is uploading the right files on S3 (with hash in the name).
I met a second problem: the URL cached is pointing to the S3 Bucket but not the Cloudfront defined in the “STATIC_URL” setting.
I think it’s related to django-storages / boto used by my custom storage which works with S3 and not Cloudfront:
(Static storage is a S3BotoStorage subclass with location sets to “static”).
Now, I have to find a way to make it works properly with Cloudfront and not S3.
Thanks for your help!
EDIT:
I figured out to make it works via this post: Django-compressor: how to write to S3, read from CloudFront?
While you define the “custom domain” key, it will use the Cloudfront domain instead of the Amazon S3.
I forgot to mention that I had to put the AWS_QUERYSTRING_AUTH to False to make it works.