I had that same issue, where it was loading some CSS I had entered a day ago, but not new CSS. I have not tried Gmuliu Gmuni's suggestion to run django-admin collectstatic
(as defined by docs). Instead, I did a hard reload in Firefox to get rid of cache, and it worked fine.
The Django documentation states that,
ManifestStaticFilesStorage
¶class storage.ManifestStaticFilesStorage¶
A subclass of the
StaticFilesStorage
storage backend which stores the file names it handles by appending the MD5 hash of the file’s content to the filename. For example, the filecss/styles.css
would also be saved ascss/styles.55e7cbb9ba48.css
.The purpose of this storage is to keep serving the old files in case some pages still refer to those files, e.g. because they are cached by you or a 3rd party proxy server. Additionally, it’s very helpful if you want to apply far future Expires headers to the deployed files to speed up the load time for subsequent page visits.
The storage backend automatically replaces the paths found in the saved files matching other saved files with the path of the cached copy (using the
post_process()
method). The regular expressions used to find those paths (django.contrib.staticfiles.storage.HashedFilesMixin.patterns
) cover:
The @import rule and url() statement of Cascading Style Sheets.
Source map comments in CSS and JavaScript files.
According to that same link (further up the page):
On subsequent
collectstatic
runs (ifSTATIC_ROOT
isn’t empty), files are copied only if they have a modified timestamp greater than the timestamp of the file inSTATIC_ROOT
. Therefore if you remove an application fromINSTALLED_APPS
, it’s a good idea to use thecollectstatic --clear
option in order to remove stale static files.
So, django-admin collectstatic
only works with an updated directory (if I'm reading this right), and my VSCode addition to the CSS file didn't update the directory timestamp when it did so for the file.
I'm new to Django, myself, so please correct me if I'm wrong.