设置为静态资源的HTTP标头的到期日或最长 [英] Set an expiry date or a maximum age in the HTTP headers for static resources
问题描述
我想提高一个ASP.NET MVC网站的性能。在这个过程中,我跑由谷歌PageSpeed Insights工具。此工具提到,我应该通过设置HTTP头到期日或最高年龄的静态资源利用浏览器缓存。
一切我在网上找指出,在IIS的配置设置。我的挑战是,这个网站是微软Azure网站。出于这个原因,我没有访问IIS这个东西鼓捣。
有没有办法对我来说,这种应用程序的到期日期添加到HTTP标头为我的静态资源?如果是这样,怎么样?
感谢您!
保护覆盖无效初始化(System.Web.Routing.RequestContext的RequestContext)
{
requestContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
requestContext.HttpContext.Response.Cache.SetMaxAge(TimeSpan.FromSeconds(3600));
requestContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddSeconds(3600));
base.Initialize(RequestContext的);
}
I'm trying to improve the performance of an ASP.NET MVC website. In the process, I ran the PageSpeed Insights tool by Google. This tool mentioned that I should leverage browser caching by setting an expiry date or a maximum age in the HTTP headers for the static resources.
Everything I find online points out configuration settings in IIS. My challenge is, this site is a Microsoft Azure Website. For that reason, I do not have access to IIS to tinker with this stuff.
Is there a way for me to add expiry dates to the HTTP headers for my static resources in this kind of app? If so, how?
Thank you!
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
requestContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
requestContext.HttpContext.Response.Cache.SetMaxAge(TimeSpan.FromSeconds(3600));
requestContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddSeconds(3600));
base.Initialize(requestContext);
}
这篇关于设置为静态资源的HTTP标头的到期日或最长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!