Django-compressor: 404 for compressed files in CACHE

Created on 7 May 2017  ·  6Comments  ·  Source: django-compressor/django-compressor

I cannot access the files that are created by django-compressor. It gets created in staticfiles/CACHE/, but when I load the page it says:

GET https://site.com/de/static/CACHE/css/5e257aa688ab.css/ 404 (Not Found)
GET https://site.com/de/static/CACHE/js/3f1c59956fa3.js/ 404 (Not Found)

Note: The original link gets redirected to the 404 page, hence the /de/ in the URL. In the source code, the following blocks are correct:

<link rel="stylesheet" href="/static/CACHE/css/5e257aa688ab.css" type="text/css" />
<script type="text/javascript" src="/static/CACHE/js/3f1c59956fa3.js"></script>

It is worth noting, that I use django-sekizai and the according postprocessor compressor.contrib.sekizai.compress.

My settings:

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

COMPRESS_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
COMPRESS_URL = STATIC_URL
COMPRESS_ENABLED = True

STATIC_ROOT = '/app/staticfiles/'  # usually computed, ends up here
STATIC_URL = '/static/'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # Django-Bower
    'compressor.finders.CompressorFinder',
)

Template tags:

{% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %}
{% render_block "js" postprocessor "compressor.contrib.sekizai.compress" %}

Can someone help me? I am stuck with this for 3 days now and countless hours...

Most helpful comment

@oesah , thanks for this. I am having the exact same issue. I realise this is not a compressor issue and that this thread is now closed, but if you have started this discussion on whitenoise please could you post a link. I've spent a few hours trying to solve this issue and this thread was a life saver!

All 6 comments

When I enable compressor locally, it works perfectly! It's just on the server, that it cannot find the files in the CACHE folder, everything else it finds.

Ok another finding: I guess the problem arises due to the combination of sekizai + whitenoise + compressor. Whitenoise Docs say that "_For performance and security reasons WhiteNoise does not check for new files after startup (unless using Django DEBUG mode). As such, all static files must be generated in advance. If you’re using Django Compressor, this can be performed using its offline compression feature._" So Sekizai compresses them in realtime (offline compression not available due to the nature of sekizai), whenever a user opens a page. Whitenoise does not search again, so it assumes the file does not exist. When I restart Django after I opened a page and the files get created, it works. But if I go to another page, I have to do the same process again (open page and restart). Then it finds them properly...

Any idea how to fix it? My next test will be to not use sekizai with the compression postprocessor, but I would love a solution that works with sekizai and realtime static requests.

So ended up modifying whitenoise.django.DjangoWhiteNoise and changed

    self.autorefresh = settings.DEBUG
    self.use_finders = settings.DEBUG

to

    self.autorefresh = True
    self.use_finders = True

And now it works. Disregarding the performance issues (which I did not notice yet, on the contrary, Google Page Speed Insight gives me one more point with autorefresh enabled..), what are the security issues? Can I circumvent those? It would be amazin, if whitenoise could also handle statics created in realtime (like django-compressor CACHE).

Hope my inputs help someone else stumbling upon this.

Hi,

This is not a compressor issue, this belongs on stackoverflow or similar (or perhaps whitenoise support forum)

Yeah I arrived at that conclusion :) Will ask the people from whitenoise. Thanks

@oesah , thanks for this. I am having the exact same issue. I realise this is not a compressor issue and that this thread is now closed, but if you have started this discussion on whitenoise please could you post a link. I've spent a few hours trying to solve this issue and this thread was a life saver!

Was this page helpful?
0 / 5 - 0 ratings