Pre-compressed static files in self host Asp.Net Core

When using StaticFileMiddleware and ResponseCompressionMiddleware, each file is read from slow disk uncompressed and then dynamically compressed (consuming CPU each time). It’s clearly ineffective in terms of CPU, disk and time.

A better approach is to pre compress some files on disk, mark them as already compressed using some kind of metadata and return them as is if compression is accepted or decompressed them dynamically.

This library provides a middelware to do it: AnderssonPeter/CompressedStaticFiles: middelware for Kestrel to serve precompressed static files.

It started with Use pre-gzipped content files? GitHub #1584.


EDIT: Also found a non core implementation. More limited but (gz only) but usefull: (it’s a StaticFilesMiddleware replacement).


How to lighten Web API in Asp.Net Core

Asp.Net Core provides a unified model for MVC and WebAPI and default templates use unified meta packages dependencies. This simplifies evolutions but we can also choose to lighten Web API using only needed dependencies. How to to it is detailed in Removing the MVC Razor dependencies from the Web API template in ASP.NET Core.

Sample code provides AddWebApi as a light version of AddMvc.