Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache
https://github.com/madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/madskristensen/WebEssentials.AspNetCore.StaticFilesWithCache
- Owner: madskristensen
- License: other
- Created: 2017-11-08T22:00:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-31T09:54:13.000Z (7 months ago)
- Last Synced: 2024-10-07T23:37:50.408Z (3 months ago)
- Language: C#
- Size: 9.77 KB
- Stars: 6
- Watchers: 2
- 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
[![Build status](https://ci.appveyor.com/api/projects/status/jy3un0oxyudrg536?svg=true)](https://ci.appveyor.com/project/madskristensen/webessentials-aspnetcore-staticfileswithcache)
[![NuGet](https://img.shields.io/nuget/v/WebEssentials.AspNetCore.StaticFilesWithCache.svg)](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.