-
Notifications
You must be signed in to change notification settings - Fork 519
Response caching: add StaticFileOptions to app.UseSpaStaticFiles() method #1424
Comments
Good idea - we'll implement this. Thanks! |
This would be awesome, but will it allow us to set cache rules per url pattern basis? @SteveSandersonMS can you please also share, when we have SSR enabled, are the files (app js bundles) being read from disk for each request? or are these cached and read from memory for subsequent requests? If the files are being read from disk for each request, wouldn't it be better if we cache the files in memory for subsequent requests? Can you please also take a look at angular/universal#811 and suggest if anything could be done at aspnet/JavaScriptServices level? |
@SteveSandersonMS @naveedahmed1 I think it would be really beneficial to have some sort of mechanism which can cache SPA resources (i.e static files and any pre-rendered responses). As I understand feature request that Steve has agreed to will cache only static resources by having ResponseCaching option in UseSpaStaticFiles middleware. On the other hand page loads (i.e document resulted in pre-rendering for each requested URL in browser address bar) have got no mechanism of caching right now. Is there a similar option that can be added in UseSPA middleware which under the hood can leverage asp.net core's caching features. In comparison we have the option of ResponseCaching attributes on Controller action methods or use tag helpers in razor views in other templates. |
Now implemented. You can now pass a
Yes, see
No, Node loads them and parses/compiles them in memory as a module only once. It doesn't have to read modules from disk on every request.
That's internal to Angular Universal - ASP.NET isn't involved in how it processes requests at that level.
ASP.NET Core middleware lets you implement caching on any request (both server-side and client-side caching). https://docs.microsoft.com/en-us/aspnet/core/performance/caching/middleware?tabs=aspnetcore2x |
Hello. How about to add StaticFileOptions to UseSpaStaticFiles() method in Angular CLI based template for response caching? May be, I did it wrong, but this approach does not working and I think, problem is in UseSpaStaticFiles method:
app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = (context) => { var headers = context.Context.Response.GetTypedHeaders(); headers.CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue { Public = true, MaxAge = TimeSpan.FromDays(365) }; } });
The text was updated successfully, but these errors were encountered: