In ASP.net 4.5 we used to be able to enable expires headers on static resources (in-turn, enabling browser caching) by adding 'ClientCache' to the web.config, something like:
<staticcontent>
<clientcache cachecontrolmode="UseMaxAge" cachecontrolmaxage="365.00:00:00" />
</staticcontent>
As referenced in http://madskristensen.net/post/cache-busting-in-aspnet
How do we do this now in ASP.net 5 when we have no web.config and Startup.cs?
In Startup.cs > Configure(IApplicationBuilder applicationBuilder, .....)
applicationBuilder.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
context.Context.Response.Headers.Add("Cache-Control", "public, max-age=2592000")
});
If you are using MVC you can use the ResponseCacheAttribute on your actions to set client cache headers. There is also a ResponseCacheFilter you can use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With