I tried this Middleware but the browser still saving files.
I want user will always get the last version of js and css files.
public void Configure(IApplicationBuilder app)
{
app.UseSession();
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
context.Context.Response.Headers.Add("Cache-Control", "no-cache")
});
}
Disabling browser cache in ASP.NET core:
Try adding an
Expires
header as well:Another approach would be to add a querystring that changes to the end of your requests in development. Middleware would not be required in this case.
Another way would be using an ASP-Attribute when you link your files in your
_Layout.cshtml
by usingasp-append-version
you will add a fresh hash everytime the file changed, so writing:will in the end lead to:
so you get caching and the latest version out of the box.