动态CSS-缓存问题? [英] Dynamic CSS - caching problem?

查看:117
本文介绍了动态CSS-缓存问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于我在SO上了解到的一种技术,我正在使用HttpHandler即时修改一些CSS(仅简单的颜色).

I am using an HttpHandler to modify some CSS (only simple colours) on the fly, based on a technique I read about on SO.

在我为用户提供指定所需颜色的选项的页面上,一切工作都很好.理想情况下,用户保存新颜色并刷新页面后,我便希望显示新颜色.但是,只有在我明确按下浏览器重新加载或F5键时,它们才会通过.

Everything works just fine expect on the page where I am giving the user the option to specify the colours they want. Ideally as soon as the user saves his new colours and the page refreshes I want the new colours to be displayed. However they only come through when I explicitly press the browser reload or F5 key.

我很欣赏某个地方(IIS或浏览器)正在对样式表进行一些有用的缓存,而这正是我想要的缓存,这是我想要的1000次中的999次.触发的HttpHandler.

I appreciate that something somewhere (IIS or the browser) is doing some helpful caching of my stylesheet which 999 times in 1000 is exactly what I want, however on this particular page event I want to be able to force a reload and cause the HttpHandler to fire.

任何人都知道这是如何工作的以及我能做什么?

Anyone understand how this works and what I can do?

我尝试过的事情:

    Response.Clear();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Expires = -1;
    Response.Cache.SetExpires(DateTime.Now.AddDays(-1));

因为我也在使用ASP.NET主题添加一个查询字符串,所以样式表链接并不是一个简单的选择.

Because I am also using ASP.NET themes adding a querystring the stylesheet link isn't really a simple option.

有没有人?

推荐答案

可以使用我在网站上使用的技术来解决资产更改后(例如在部署之后)重新加载资产的问题.

This can be solved with technique that I use on my sites to cause reloads of assets once they have changed, such as after a deploy.

?value附加到CSS URL的末尾,其中value对应于版本或浏览器尚未看到的某些唯一值.在我的情况下,我使用文件修改时间,但是在您的情况下,由于CSS几乎在每个页面加载时都是动态的,因此我建议生成一些唯一值.

Append ?value to the end of your CSS url, where value corresponds to the version, or some unique value the browser hasn't seen yet. In my case I use the file modification time, however in your case since the CSS is dynamic on almost every pageload, I suggest generating some unique value.

由于URL始终不同,因此浏览器将始终重新加载该URL,并且永远不会将其放入其缓存中.

Since the URL is always different, the browser will always reload it and it will never get put into its cache.

这篇关于动态CSS-缓存问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆