Skip to content

Commit

Permalink
Instruct the browser to not cache "service-worker-assets.js" (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
miladsoft authored Mar 24, 2023
1 parent a7ed610 commit 3d0ed2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<BlazorCacheBootResources>false</BlazorCacheBootResources>
<DisableGitAutoCRLFInPublishOutput>true</DisableGitAutoCRLFInPublishOutput>
<RunAOTCompilation>true</RunAOTCompilation>
<ImplicitUsings>enable</ImplicitUsings>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore.AtomicSwaps.Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1 class="mt-5">Blockcore Atomic Swaps</h1>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<!--<script src="js/index.js"></script>-->
<script>navigator.serviceWorker.register('service-worker.js');</script>
<script>navigator.serviceWorker.register('/service-worker.js', { updateViaCache: 'none' });</script>
</body>

</html>
15 changes: 13 additions & 2 deletions src/Blockcore.AtomicSwaps.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddSwaggerGen();
builder.Services.Configure<TelegramLoggingBotOptions>(options =>builder.Configuration.GetSection("TelegramLoggingBot").Bind(options));
builder.Services.Configure<TelegramLoggingBotOptions>(options => builder.Configuration.GetSection("TelegramLoggingBot").Bind(options));
builder.Services.AddSingleton<ITelegramBotService, TelegramBotService>();

builder.Services.Configure<DataConfigOptions>(options => builder.Configuration.GetSection("DataConfig").Bind(options));
Expand All @@ -29,7 +29,18 @@
}

app.UseBlazorFrameworkFiles();
app.UseStaticFiles();

app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
{
if (context.File.Name == "service-worker-assets.js")
{
context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
context.Context.Response.Headers.Add("Expires", "-1");
}
}
});

app.UseRouting();

Expand Down

0 comments on commit 3d0ed2c

Please sign in to comment.