Last post Apr 14, 2020 07:38 PM by carboneum
Apr 13, 2020 06:35 PM|carboneum|LINK
I am using the Angular project template with ASP.NET Core. Reference
The caching should be enabled by default, to be sure I have added an StaticFileOptions object to the StaticfileMiddleware:
public class Startup
OnPrepareResponse = ctx =>
const int durationInSeconds = 60 * 60 * 24;
"public,max-age=" + durationInSeconds;
Then I have created an test.html in wwwroot folder.
<title>Test static files</title>
This is a test for static files!
When I dotnet run and navigate to https://localhost:5001/test.html the page is displayed correctly.
After I change the html page, I click to google chrome's address bar and press enter, to issue another HTTP request to the test.html file. I have not reload the page.
You can see that the change is reflected by google chrome and I received an status 200 again instead of 304. Cache-control in the Response Header is public,max-age=86400. Why does the static file caching not work? My desired result would be that the change
is not reflected after the second HTTP request, so I can be sure static file caching is working properly.
I am using: .NET Core SDK 3.1.201 and Chrome 80.0.3987.163.
Apr 13, 2020 07:51 PM|bruce (sqlwork.com)|LINK
chrome shows the caching headers where sent correctly. but typically chrome ignore caching when the debug tools are open.
try your test with the debug tools closed. (also do not use F5 which means ignore cache).
Apr 14, 2020 07:38 PM|carboneum|LINK
Thank you bruce. Unfortunately I couldn't manage to test the static file caching by closing the DevTools. I found the solution. You have to trust the ASP.NET Core HTTPS development certificate. Click
here for details and then run the application. Navigate to your static file. Open a new tab in Chrome. Open the Chrome DevTools by pressing F12. Type the URL into the address bar or copy and paste it from the previous tab. It works!