Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cache-Control: no-cache; to Static Web Assets #37

Merged
merged 1 commit into from
Oct 3, 2023
Merged

Add Cache-Control: no-cache; to Static Web Assets #37

merged 1 commit into from
Oct 3, 2023

Conversation

tlmii
Copy link
Member

@tlmii tlmii commented Oct 3, 2023

Fixes https://github.com/dotnet/astra/issues/705.

Static Web Assets middleware currently sets the ETag and Last-Modified headers, but it does not set the Cache-Control header to no-cache. This means that in some (many? most?) cases the browser ignores the ETag and Last-Modified headers and always pulls the asset from cache.

dotnet/aspnetcore#44153 has been re-opened to potentially address this in the middleware itself. But for now, we can use the StaticFileOptions parameter of UseStaticFiles to add the header ourself if we see that it's not set to anything else.

// ETag and Last-Modified headers will be respected by the browser.
// This may be able to be removed if https://github.com/dotnet/aspnetcore/issues/44153
// is fixed to make this the default
if (context.Context.Response.Headers.CacheControl.Count == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this only in dev env?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is relevant regardless isn't it? If the user updates their Aspire.Dashboard nuget package, the URL for, say, LogViewer.razor.js in the browser will still be the same and possibly cached, no matter what environment is set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree - without this header, the same caching issues would occur in prod too, which is worse still.

@tlmii tlmii merged commit 9207f44 into dotnet:main Oct 3, 2023
4 checks passed
@tlmii tlmii deleted the dev/cache-control branch October 3, 2023 06:29
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants