https://github.com/madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache
https://github.com/madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache
- Owner: madskristensen
- License: other
- Created: 2017-11-08T22:00:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-31T09:54:13.000Z (11 months ago)
- Last Synced: 2025-03-11T16:40:32.326Z (about 1 month ago)
- Language: C#
- Size: 9.77 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache - (C\#)
README
# ASP.NET Core Static Files with caching
[](https://ci.appveyor.com/project/madskristensen/webessentials-aspnetcore-staticfileswithcache)
[](https://nuget.org/packages/WebEssentials.AspNetCore.StaticFilesWithCache/)Middleware for ASP.NET Core that enables static files and adds client-side caching headers.
## Features
Here's what the middleware does:- Customize the expiration time span
- Adds both `cache-control` and `expires` headers
- Adds `cache-control: immutable` for fingerprinted files## Register the middleware
Where you normally registers to use the `app.UseStaticFiles()` middleware, instead replace it with this:```c#
public void Configure(IApplicationBuilder app)
{
app.UseStaticFilesWithCache();
}
```To specify the cache expiration time, pass the method a `TimeSpan` like so:
```c#
public void Configure(IApplicationBuilder app)
{
app.UseStaticFilesWithCache(TimeSpan.FromDays(30));
}
```This will tell the browsers to cache the static file for 30 days.