当我更新我的网站时,运行npm run build并将新文件上传到服务器我仍在查看我的网站的旧版本.我的项目的回购是 https://github.com/Alfrex92/serverlessapps
没有React,我可以看到我的网站的新版本缓存破坏.我这样做:
上一个文件
<link rel="stylesheet" href="/css/styles.css">
Run Code Online (Sandbox Code Playgroud)
新文件
<link rel="stylesheet" href="/css/styles.css?abcde">
Run Code Online (Sandbox Code Playgroud)
我怎么能做这样的事情或用create react app实现缓存清除?
在创建的github中有许多线程对此做出反应,但没有人有正确/简单的答案.
我尝试过这个中间件,但浏览器仍在保存文件.
我希望用户将始终获得js和css文件的最新版本.
public void Configure(IApplicationBuilder app)
{
app.UseSession();
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
context.Context.Response.Headers.Add("Cache-Control", "no-cache")
});
}
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试index.html使用 .NET Core 2.2 后端为我的 Angular SPA禁用缓存。
我根据这个答案通过OnPrepareResponse为我的StaticFileOptions.
但是Cache-Control标头永远不会被发送。当我在 OnPrepareResponse 操作中设置断点时,我会为每个文件中断,除了 index.html
我在这里缺少什么?我怎样才能真正控制index.html文件的缓存?
// I've changed nothing else in the default ASP.NET Core/Angular template
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = context =>
{
// Breakpoint for next line hits for following files
// 1: styles.61d14a95058dbe9da495.css
// 2: runtime.a66f828dca56eeb90e02.js
// 3: polyfills.7a0e6866a34e280f49e7.js
// 4: main.d9791b5a6df420d81994.js
// 5: …Run Code Online (Sandbox Code Playgroud) angular ×1
asp.net ×1
asp.net-core ×1
c# ×1
caching ×1
node.js ×1
react-redux ×1
reactjs ×1
typescript ×1