-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
React template index.html caching? #3147
Comments
Hi. It looks like this is a question about how to use ASP.NET Core. While we do our best to look through all the issues filed here, to get a faster response we suggest posting your questions to StackOverflow using the asp.net-core-mvc tag. |
@georgiosd, you can configure the |
@mkArtakMSFT the SPA templates use |
@mkArtakMSFT I could have been more specific :) |
As long as the If you choose to pass a custom I'm not totally sure what you mean by |
Actually I think the confusion is on my end. I was referring to:
But that seems to be a different call. The relevant one is:
@SteveSandersonMS is the call to |
Looks like this issue is troubling more people: facebook/create-react-app#1910 Any many more... This seems to be because of the service worker from CRA so the cache settings I added don't seem to have much of an effect. If you have any ideas let me know :) |
This setup works for me (Create React App hosted on Azure App Service). app.UseSpaStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = ctx =>
{
if (ctx.Context.Request.Path.StartsWithSegments("/static"))
{
// Cache all static resources for 1 year (versioned filenames)
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromDays(365)
};
}
else
{
// Do not cache explicit `/index.html` or any other files. See also: `DefaultPageStaticFileOptions` below for implicit "/index.html"
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromDays(0)
};
}
}
}); app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions()
{
OnPrepareResponse = ctx => {
// Do not cache implicit `/index.html`. See also: `UseSpaStaticFiles` above
var headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromDays(0)
};
}
};
if (env.IsDevelopment())
{
//spa.UseReactDevelopmentServer(npmScript: "start");
spa.UseProxyToSpaDevelopmentServer("http://localhost:3000");
}
});
The main issue I had before making this change was because there was not an explicit
|
I can confirm that @techniq 's solution also works for me. Thanks! |
Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments. |
I tried the solution from @techniq but it is now working, and breakpoints in |
Hi,
I seem to be facing a problem when deploying a new build to my server.
It seems that index.html is cached by the browser and tries to load the old bundle, which leads to a 404.
Any ideas how to fix this?
Thanks!
The text was updated successfully, but these errors were encountered: