1

I am writing an ASP.NET Core MVC site and using my own JavaScript library, which I edit frequently.

The problem is that sometimes the modifications to the file don’t show up in the browser, even though I see them while debugging.

Renaming the file helps. Capitalizing/lowering the first letter helped only once. Deleting the browser cache doesn't help. The browser is the last version of Opera, and I would prefer not to change it.

I'll be very glad if somebody has an idea on how to fix this.

Jeremy Caney
  • 4,585
  • 13
  • 32
  • 54

2 Answers2

1

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.

Jeremy Caney
  • 4,585
  • 13
  • 32
  • 54
0

Have you already tried to refresh your cache? It is usually CTRL-F5 (Google Chrome)

Stebeber
  • 60
  • 6