I find it suspicious that clearing your browser cache isn’t resolving the issue. That suggests there may be another source of caching, possibly on the server—or, at least, between you and the server. This raises a couple of questions:
- Are you using output caching on your website?
- Is your JavaScript precompiled (e.g., via TypeScript or Babel)?
Regardless, the textbook solution to this in ASP.NET Core is to implement the AppendVersion
property of the ScriptTagHelper
, as follows:
<script type="text/javascript" src="~/Shared/Script.js" asp-append-version="true"></script>
This will automatically append a unique query string to your script name by calculating an SHA256 hash of your file. Each time your file is modified, a new hash is generated. The output, for instance, might look like:
<script type="text/javascript" src="/Shared/Script.js?v=Ct6ZXzHiOuQJzhBoHlSlNyN1_d3jJnz2DvRs-5xyyJs"></script>
This helps ensure that the latest version is always downloaded by browsers. It’s similar to renaming your file each time you change it, except the tag helper is taking care of that on your behalf.
Note: There’s also an analogous tag helper for <link>
and <img>
, should you need to apply something similar to your CSS or inline images.
That said, as mentioned at the top: If your HTML output is being aggressively cached at some level, you may still encounter issues.