user3284007
user3284007

Reputation: 1717

Set an expiry date or a maximum age in the HTTP headers for static resources

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!

Upvotes: 1

Views: 1566

Answers (1)

Imamul Karim Tonmoy
Imamul Karim Tonmoy

Reputation: 584

        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);
    }

Upvotes: 2

Related Questions