I am using Web Worker to run a task:
worker = new Worker("/js/worker-media.js");
However, I want to add the version of it to ensure proper update. I am using this:
// HTML
<div id="loader"
data-url="@(this.AddFileVersionToPath("/js/worker-media.js"))"
class="d-none"></div>
// Javascript
function loadWorker() {
var workerUrl = document.getElementById("loader")
.getAttribute("data-url");
worker = new Worker(workerUrl);
}
My question is that, currently I am making my own implementation of AddFileVersionToPath
(below). Is there already something built-in to get a file path with appended version?
public static class IRazorPageExtensions
{
public static string AddFileVersionToPath(this IRazorPage page, string path)
{
var context = page.ViewContext.HttpContext;
var cache = context.RequestServices.GetRequiredService<IMemoryCache>();
var hostingEnvironment = context.RequestServices.GetRequiredService<IHostingEnvironment>();
var versionProvider = new FileVersionProvider(hostingEnvironment.WebRootFileProvider, cache, context.Request.Path);
return versionProvider.AddFileVersionToPath(path);
}
}