Thursday, July 20, 2017

Caching your static files in ASP.NET Core

In ASP.NET Core static files(images, css,…) are typically served using the Static file middleware. The static file middleware can be configured by adding a dependency on the Microsoft.AspNetCore.StaticFiles package to your project and then calling the UseStaticFiles extension method from Startup.Configure:

Unfortunately this code will not do its job in the most efficient way. By default, no caching is applied meaning that the browser will request these files again and again increasing the load on your server.

Luckily it’s not that hard to change the middleware configuration to introduce caching. In this example we set the caching to one day:

Remark: An alternative approach would be to let your proxy server(IIS,…) handle the static file requests as discussed here.

3 comments:

Vcom Infotech Company said...

Wow, amazing and informative post share about the ASP.NET core. Thanks a lot. portal solution provider in coimbatore | best infotech company in coimbatore | best logo design company

mahalyasree said...

I’ve been browsing on-line greater than three hours today, but I never discovered any attention-grabbing article like yours. It is beautiful worth sufficient for me. Personally, if all webmasters and bloggers made good content material as you did, the net will be a lot more helpful than ever before.
Architectural Firms in Chennai
Architects in Chennai

Designpluz said...

It is a great sharing...I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. Web Design Sydney ,Logo Design Sydney