Wednesday, May 16, 2018

How may I turn off the caching of static files in a .NET Core Angular 5 application?

Per "ASP.NET Core 2 and Angular 5" by Valerio De Sanctis is you change this line of Startup.cs...


app.UseStaticFiles(new StaticFileOptions()
   OnPrepareResponse = (context) =>
      context.Context.Response.Headers["Cache-Control"] = "no-cache, no-store";
      context.Context.Response.Headers["Pragma"] = "no-cache";
      context.Context.Response.Headers["Expires"] = "-1";


...supposedly that does the trick. It really didn't do anything for me. "Pragma" implies use of pragmatic or implementation-dependent features I bet.


Addendum 5/17/2018: "max-age=3600", "cache", and null would be some alterative settings for the three settings above that would empower caching instead of turning it off.

No comments:

Post a Comment