I have this code to refer to my CSS script in my base.html
for my Django project:
<link href="{% static 'css/project.css' %}" rel="stylesheet">
The problem is that whenever I add or remove styling from project.css
, it doesn’t update when I run the server.
I know this happens because every time the page loads the browser cache will think it’s seen the file before and reload the cached version from disk. I also know a solution is to change the CSS filename every time I make an update.
Is there an easier way to reload the CSS file every time I refresh my browser?
Your browser may be caching the css files within the browser, preventing the changes from being loaded. Try doing a “full” page refresh. On Windows in either Chrome or Firefox, hold down either the shift or ctrl key and click on the reload icon (the “circle arrow”), or do a ctrl-F5 (reload key).
Browser Cache If you are adding/modifying in-line CSS or JavaScript and not seeing the changes reflected in the HTML source, the page is likely being cached. The solution may be to purge the WordPress object cache, which stores our page caching (Batcache) renders.
Including CSS in Django TemplateWe need to load the static files by adding the below line of code at the top of the template (. HTML) file. Then, insert the stylesheet in the HTML using link HTML tag. If you are new to the HTML and CSS, you can learn more about adding CSS in HTML code.
You can bypass the cache using ctrl + F5
for detailed reference: https://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache
You have to click on Ctrl + f5 every time to update your CSS, which isn't dope. You can actually do something like this:
<link rel="stylesheet" href="/static/css/mycss.css?{% now "U" %}"/>
The {% now "U" %} will generate a random timestamp which updates your CSS every time you reload the page. I hope this works.
For better understanding check out: click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With