参见英文答案 >
What does ‘?’ do in a Css link?
如果你看看Stackoverflow.com的来源,你会看到他们的css文件的引用是:
如果你看看Stackoverflow.com的来源,你会看到他们的css文件的引用是:
<link href="/Content/all.min.css?v=2383" rel="stylesheet" type="text/css" />
解决方法
This (PHP example)文章解释一下你背后的想法。基本上,您可以发现上次修改文件的时间戳。这样,每当您更改CSS时,查询字符串将会更改,“强制”浏览器下载新版本。这对于CSS和JS文件都是有效的。
ASP.NET示例是这样的:
public static string GetBreaker(string fileName) { string cacheBreaker = null; try { if (fileName.StartsWith("~")) { fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,fileName.Remove(0)); } cacheBreaker = File.GetLastWriteTime(fileName).ToFileTime().ToString(); } catch { } return string.IsNullOrEmpty(cacheBreaker) ? string.Empty : string.Format("?cachebreaker={0}",cacheBreaker); }
<link href="<%= this.ResolveClientUrl("~/CSS/style.css") %><%=CacheBreaker.GetBreaker("~/CSS/style.css") %>" rel="stylesheet" type="text/css" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。