Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 for compressed files in CACHE #847

Closed
oesah opened this issue May 7, 2017 · 8 comments
Closed

404 for compressed files in CACHE #847

oesah opened this issue May 7, 2017 · 8 comments

Comments

@oesah
Copy link

oesah commented May 7, 2017

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...

@oesah
Copy link
Author

oesah commented May 8, 2017

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.

@oesah
Copy link
Author

oesah commented May 8, 2017

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.

@oesah
Copy link
Author

oesah commented May 9, 2017

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.

@diox
Copy link
Member

diox commented May 9, 2017

Hi,

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

@diox diox closed this as completed May 9, 2017
@oesah
Copy link
Author

oesah commented May 9, 2017

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

@zengoma
Copy link

zengoma commented Dec 1, 2017

@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!

@sergioisidoro
Copy link

For people who bump into this:

https://whitenoise.evans.io/en/stable/django.html#django-compressor
https://django-compressor.readthedocs.io/en/latest/usage/#offline-compression

TL:DR

# In settings
COMPRESS_OFFLINE=True 
# In your build process
python manage.py compress --force
python manage.py collectstatic --noinput

#486 (comment)

@eabdollahian
Copy link

For people who bump into this:

https://whitenoise.evans.io/en/stable/django.html#django-compressor https://django-compressor.readthedocs.io/en/latest/usage/#offline-compression

TL:DR

# In settings
COMPRESS_OFFLINE=True 
# In your build process
python manage.py compress --force
python manage.py collectstatic --noinput

#486 (comment)

thanks. this work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants