Git Product home page Git Product logo

Comments (6)

evansd avatar evansd commented on September 7, 2024

I've not used django-assets before but from a brief look at how it works I suspect that the problem is that it tries to generate the bundle files at runtime, the first time template is rendered, rather than generating everything beforehand.

WhiteNoise expects all static files to be in place at the time the application starts, so it won't pick up the files which are added afterwards.

It looks like django-assets has a ./manage.py assets build command which can be used to generate the bundles upfront. If you use this then I think it should work. Generating assets at runtime is a bad pattern anyway, in my opinion.

Also, looking at those example URLs you've given, you're using django-assets versioning for your bundles which appends the version as query parameter, rather than making it part of the filename.

This will work with WhiteNoise, but you'll get better caching behaviour if you use Django's built-in versioning. The docs suggest that should work OK with django-assets:
http://django-assets.readthedocs.org/en/latest/staticfiles.html#cachedstaticfilestorage

from whitenoise.

lfrodrigues avatar lfrodrigues commented on September 7, 2024

I'm running with DEBUG=False so it does not try to generate files at runtime, the correct bundle files and whitenoise hashed files are generated with collectstatic.

Post-processed '/(MYPATH)/gen/packed.css' as '(MYPATH)/gen/packed.f76d4cf5e04f.css'

I'm using
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

so I guess the correct names of files should be used.

Any other insight?

from whitenoise.

evansd avatar evansd commented on September 7, 2024

Hmm... that looks right. Are you running this on Heroku? If so, when in the build process is ./manage.py assets build getting run?

The basic rule is that anything that's in STATIC_ROOT at the point the application starts will get served by WhiteNoise. So if a file is not getting served, it will be because for some reason it's not in the right place and the right time.

from whitenoise.

lfrodrigues avatar lfrodrigues commented on September 7, 2024

Running using gunicorn on my local machine.
Yes all is in the STATIC_ROOT because I ran collectstatic before.

I'm starting to think that the problem might me django-assets because when I run
curl -I 127.0.0.1:8000/static/gen/packed.5df0a1aaf07a.js whitenoise is serving the file.

from whitenoise.

lfrodrigues avatar lfrodrigues commented on September 7, 2024

@evansd What assets packing/minification solution do you use with whitenoise?

from whitenoise.

evansd avatar evansd commented on September 7, 2024

I'm using gulp. I just get gulp to write all it's files into a static_build directory which is listed in my STATICFILES_DIRS settting. Then contrib.staticfiles handles the versioning. Works well for me.

from whitenoise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.