问题描述
我要版本号添加到CSS文件的生产环境不给力,用户每次preSS按Ctrl + F5新版本部署在督促服务器后,作为老版本的浏览器缓存下载新的CSS文件。
I want to add version number to CSS files for production environment not to force user every time press Ctrl+F5 to download new CSS files after new version is deployed in prod server as the old version is cached in browser.
我添加版本号作为查询字符串参数是这样的。
I'm adding build number as querystring param like this.
link href="Styles/jquery.Autocomplete.css?<%= Globals.BuildNumber %>" rel="stylesheet" type="text/css"
,但输出是这
link href="../../Styles/jquery.Autocomplete.css?<%= Globals.BuildNumber %>"
看起来是小脚本是不是在head标签的工作,因为这是在body标签的罚款。
Looks that scriptlet is not working in head tag, as this is fine in body tag.
推荐答案
它不记录任何地方,但你发现它不会出现的支持的的。下面就来解决这个问题的方法。 (如果它不是很明显,它应该在code隐藏文件去):
It's not documented anywhere, but as you've found out it doesn't appear that HtmlHead supports embedded code blocks. Here's one way to get around that. (if it's not obvious, it should go in your code-behind file):
const int BuildNumber = 1;
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// add style sheet
Header.Controls.Add(new Literal() {
Text = string.Format(
@"<link rel='stylesheet' type='text/css' href='custom.css?{0}' />",
BuildNumber
)
});
}
这篇关于小脚本是不是在头标记工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!