0

Firstly I've tried most of the solutions suggested in Stack and from Google. None of the below solutions work when DEBUG MODE is off.

  • sudo systemctl daemon-reload , sudo systemctl restart gunicorn to make sure its not a gunicorn issue
  • Turned off all caching from nginx. Made sure this was the case with
curl -I "https://swjungle.shop/2static/CACHE/css/output.9291a1ea98ad.css"
returns 
Cache-Control: no-cache
  • Checked Nginx config again. If debug=True the static files are still not reloaded until collectstatic. But after collectstatic it works. .staticfiles is my STATIC_ROOT
 location /2static {
    alias /home/.staticfiles;
}
  • sudo systemctl restart nginx also does not reload caching
  • My browser caching is off and I did a hard reload , Ctrl + F5. Deleted all cookie.

None of it works... Struggling to find a solution.

Here is my settings.py for cache stoarge

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
INSTALLED_APPS += ["compressor"]
STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "compressor.finders.CompressorFinder"

STATIC_URL = '/2static/'
STATIC_DIR = str(ROOT_DIR / "2static")
STATICFILES_DIRS = [
    STATIC_DIR,
]
STATIC_ROOT = str(ROOT_DIR / ".staticfiles")

After moving css file out of compress block - hashed css file is created in .staticfiles but browser still searches for the old hash css file DIR of CSS

Turtle SK
  • 29
  • 6
  • 1
    That CSS name implies that you are using a combining tool such as `django-compress`. In that case the file name should change when you make a change to one of your CSS files. If you are still seeing the same hash (`9291a1ea98ad`) in your HTML it means that there is something wrong with the compressor. Are you using automatic compression or manual? – Selcuk Apr 16 '21 at 01:38
  • Thanks for the response. I'm using django-compress. I've also moved the css file out of the {% compress css %} block and did the above including collectstatic but the changes are still not reflected. So I figured that was not issue. When I collect static changes are reflected in .staticfiles/header.css but a new hashing of reflected changes are not created. The old one is still used. – Turtle SK Apr 16 '21 at 01:53
  • What kind of change did you do and where, point of collectstatic is to deploy static files from project to STATIC_ROOT directory so this is normal behaviour – iklinac Apr 16 '21 at 01:53
  • Moreover Nginix is not forwarding static location to Django server for Debug=True to have any effect regarding serving of static files – iklinac Apr 16 '21 at 01:57
  • Browser is loading the files from the hashed css header.9447bdae27b7.css and not from the header.css which is in STATIC_ROOT DIR. I guess this is normal behavior but shouldn't a new hashed css be created in STATIC_ROOT when I make changes and run collectstatic command? – Turtle SK Apr 16 '21 at 01:59
  • Seems that this issue is not related to Nginx at all but a problem for django. This seems to be related case. https://stackoverflow.com/questions/45816474/manifeststaticfilesstorage-still-fetching-old-static-file-even-when-staticfile Based on the recommendation from the answer given should I have restart gunicorn every time there is a change in my static files? Is there a safer way considering that css files changed quite frequently and served in production. Or should I edit the css hash file in .staticfiles folder? – Turtle SK Apr 16 '21 at 06:59

0 Answers0