It looks like I’m facing cache issues so I would like to implement this cache busting feature as it was recommended to me. As I’m not comfortable at all with all of this stuff and static files management, I would like to double check the process and understand how I could test it before pushing to production.
The context: my application is already in a production server (alpha version) and as this is an evolution of the ground settings, I would like to take this opportunity to train myself to prepare, test and deliver such technical updates. I’ll take the opportunity to better understand static files management. Currently, the js and css files are not properly propagated and my production app still uses older versions, so I need to enforce a server cache refresh.
How to proceed
As far as I understand, what I have to do is to change my settings file and add the following line:
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
I’m wondering if I need to change anything else. Here are my current settings about static files management:
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = []
I’ve mainly seen several approaches for STATICFILES_DIRS
(either []
or ./myapp/static
or (os.path.join(BASE_DIR, "my_project", "static"), )
) but I do not know the differences, and what is the better setting
I’ve read some use cases where it was recommended to ‘reinit’ the settings: delete the static directory and rebuild everything (migrations, collect static), and I wonder if it’s necessary? Shall I run python manage.py collectstatic
? Anything else?
How to test
The key parameter to activate this feature is to set DEBUG = False
Can I test this modification directly in my local development environment? To check if it works, is it enough to make small changes within js / css and ensure these changes are applied?
How to deploy
Are there any dedicated manipulations to perform?
I mean, I will pull the committed changes and reload gunicorn service as usual), am I supposed to do anything else?
Many thanks for your advises, again I’m not comfortable with such subject and I hope it will help other newbies like I am ^^