0

We have an ASP MVC 5 applications. We use bundles with optimization enabled by default. But we have heard several times from users, that they get errors, that we think are caused by old versions of user scripts. Their browsers somehow take scripts from cache, despite the fact, that we have edited that script files and bundles should be updated. The worst part of the problem is that we can't imitate or recreate this problem. We don't know how. We already have tried to make test-changes to scripts like adding some "console.log('test')" lines in order to see, if the browser takes the cached version, but everything was ok, the hash in the end of <script src="....?v='hash'"> changed and the browser took the newest version from first time. I should mention, that our site is a single page application. Don't know, maybe its somehow related with the problem. Have you faced this kind of problem?

1 Answers1

1

There's not enough information here to give a definitive answer. The bundler detects changes in files and will regenerate the bundle along with the link to that bundle, which will include an updated query string param. Since the query string is part of the URI, it's considered a totally different resource at this point, and the browser should fetch it again, because there is technically no cache available. The only logical reason this would not occur is if the HTML with the link to the bundle is not being updated. This can happen if you're using OutputCache or otherwise caching the HTML document. It can also happen if the client's browser is aggressively caching the HTML document. Unfortunately, there's not much you can do about that, as the client browser ultimately has control over what is or is not cached and for how long.

That said, given that this is a single page app, it's very possible that it's also including a cache manifest. This manifest will very often include the HTML file itself, and the browser will not refetch any file in the manifest unless the manifest itself is updated.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • We are not using `OutputCache` anywhere. I have checked the "query string in the end of script URI not updating" scenario in several browsers and everything is ok, its updating normally. I'll read about cache manifest and write, if something will change – Elnur Mamedov Feb 14 '17 at 14:07
  • Well, you already said it's working fine for *you*. The affected users, when affected, are not getting updated HTML, for some reason. Unfortunately, because of the transient nature, things like this are often extremely difficult to track down or explain. You can look into send no-cache headers for the HTML document(s). That will cause it to always be requested, even if it could be cached temporarily, but at least it might prevent it from being cached when it shouldn't be (see: http://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers#2068407). – Chris Pratt Feb 14 '17 at 14:13
  • But its very strange, because we have tested with the same browsers that our users use(some of users are from our non-techical team). I've already read about no-cache, but that's not suitable for us :( Our pages are several megabytes, we don't want users to download them everytime – Elnur Mamedov Feb 14 '17 at 14:17
  • Sheesh. Several megabytes for an HTML document? If that's truly the case you need to factor some of that out. You can load in templates and such externally. You main document should just be a skeleton that wires everything up. – Chris Pratt Feb 14 '17 at 14:33