I have a js module, let's call it A. It uses versioning by appending ?v=xxxxxxxxxxxx into its URL (like <script src="/Scripts/A.js?v=637082108844148373"></script>). v changes everytime we make changes in the file.
Here is the code:
public static class UrlHelperExtensions
{
public static string Content(this UrlHelper helper, string filename, bool versioned)
{
var result = filename;
if (versioned)
{
var lastWriteTimeToken = CalculateToken(helper.RequestContext.HttpContext, filename);
result = filename + "?v=" + lastWriteTimeToken;
}
return helper.Content(result);
}
}
And then we can use it in Razor views as this:
// Sample.cshtml
// ... code omitted for the sake of brevity ...
@section scripts {
<script type="module" src="@Url.Content("~/Scripts/A.js", true)"></script>
}
// ... code omitted for the sake of brevity ...
The module imports modules B.js and C.js:
// A.js
import {Foo} from "./B.js";
import {Bar} from "./C.js";
If I change something in module A.js, client browser's cache is busted since we have ?v parameter which is changing every time we make any changes in A.js. But if I change something in module B.js or C.js, its version remains the same and I have to clear cache manually (CTRL + F5) to see the changes.
In other words, we can't use ?v parameter for the lines:
import {Foo} from "./B.js";
import {Bar} from "./C.js";
How to solve this problem of cache busting for imported files in MVC 5?