开发者

django css file cached

I'm having a css file and i want to modify it to fit my needs. The problem is that it seems to be cached 开发者_JS百科somewhere, as i just cannot see the changes, no matter what i do in the css file. I am sure i am pointing to the right file, as by now i'v modified in it, and it worked. Is there any setting so that i can turn the cache off? Thanks!


Just go into your site, view source, and copy the link to your CSS file. Verify the link, verify it's being modified. Refresh the CSS file manually via your browser to get the latest.

This isn't a Django issue.


As pointed out in this article http://www.wkoorts.com/wkblog/2009/07/12/css-auto-reload-with-django-templates/, you could force django reload your css file by using a parameter in your css link :

<link rel="stylesheet" type="text/css" href="/site_media/css/style.css?{% now "U" %}" />

This is a timestamp which takes a different value every second, so you could even reload your css second every second if needed!


Did you try appending a datetime stamp to the end of the request? I know some frameworks do this to .js and .css files automatically to prevent caching.


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 file, change this version in the template, so browser will be forced to reload the file.

Of course you can use even now as suggested by @rom, but if your static files are not being changed very often, it's not the smartest idea to don't use cache at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜