This is annoying. I have a javascript file referenced on a django template:
"Changes of staticfiles is not working". There can be multiple reasons for that.
Your browser is storing cache
of your static files.
Solution (1): Open Incognito/Private window
Solution (2): Use hard refresh:
cmd + shift + r
ctr + shift + r
If you're facing this issue in production then follow the steps below:
Remove staticfiles
folder by following command:
sudo rm -rf staticfiles
[inside your project directory]
Now run collectstatic
command: python3 manage.py collectstatic
Restart gunicorn
, by following command: sudo systemctl restart gunicorn
Restart nginx
, by following command: sudo systemctl restart nginx
Sometimes browser stores thes staticfiles data (as caches) for a certain time. After couple of hours the problem may gone.
Hope this will fix you issue.
Clearing static file python manage.py collectstatic --noinput --clear
. This will clear the statics beforehand.
Clear the browser cache
Add a random string after the js file include, e.g jquery.js?rand=23423423, with each load.
Did it help?
Instead of using complicated solutions you can add extra parameter to your includes in the templates.
For static includes:
<script src="{% static 'js/polls/polls.js' %}?version=1"></script>
For direct includes:
<link rel="stylesheet" type="text/css" href="/site_media/css/style.css?version=1" />
Note the ?version=1
in the code. Every time you're modifying the css/js file, change this version in the template, so browser will be forced to reload the file.
And if you want to avoid caching at all for some unknown reason, you may use the current timestamp instead of version:
<link rel="stylesheet" type="text/css" href="/site_media/css/style.css?{% now "U" %}" />