admin管理员组文章数量:1384098
I'm doing a project in Django and using djangos-css () and Sass (/). The Sass files are served in development using django-css. I want to write a JavaScript routine that will every one second retrieve the CSS assets. The purpose of this is so that the designer can edit the Sass files, hit save, and see the result in the browser immediately without switching applications and hitting refresh.
Basically I need a way for JavaScript to force the browser to re-download certain files without doing a page refresh. Is this possible?
I'm doing a project in Django and using djangos-css (http://github./dziegler/django-css) and Sass (http://sass-lang./). The Sass files are served in development using django-css. I want to write a JavaScript routine that will every one second retrieve the CSS assets. The purpose of this is so that the designer can edit the Sass files, hit save, and see the result in the browser immediately without switching applications and hitting refresh.
Basically I need a way for JavaScript to force the browser to re-download certain files without doing a page refresh. Is this possible?
Share Improve this question edited Jan 31, 2010 at 0:30 hekevintran asked Jan 30, 2010 at 20:43 hekevintranhekevintran 23.7k34 gold badges116 silver badges182 bronze badges2 Answers
Reset to default 3The simplest way is usually to add a unique parameter onto the url, I often just use a timestamp
var timestamp = (new Date()).getTime();
url += '?time=' + timestamp;
Just be careful if your requests already have parameters then you need to add &time=' + timstamp
instead.
The browser can't cache the request because each request looks unique.
Not all caches will cache content with a query string.
Steve Souders remends, “…avoiding a querystring for cacheable resources”. He found that in this case 5-20% of requests will not be cached. Query strings in particular do not work at all with some CDNs for cache invalidation.
The better way is to generate a MD5 with the javascript file name for each release e.g.
{path to script file}/filename-{md5 hash}.js
本文标签: cssUsing JavaScript to invalidate the browser39s cacheStack Overflow
版权声明:本文标题:css - Using JavaScript to invalidate the browser's cache - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744519900a2610392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论