15

I have an ASP.NET MVC4 application that (I think) has been working correctly with JavaScript and CSS bundling since it was first published one year ago. During that period, we have published numerous updates and seen no evidence of problems with script delivery.

However, with our latest code deployment, I noticed that the served JavaScript is not up-to-date and that the querystring parameter used in the request for the script bundle does not change, regardless of changes to the underlying script content.

I have tried rebuilding the solution in Visual Studio and verified that the modified script files are being correctly deployed to the server. I have also explicitly recycled the IIS application pool and restarted the server, but the problem persists.

Any ideas how to diagnose or fix this issue please?

UPDATE: Having just compared the staging and production servers, I notice a difference in behavior. Both servers are deployed to in the same manner, using Visual Studio web deploy. The staging server correctly and immediately reflects changes to script files, by updating the hashes that it uses in the URLs that reference script bundles. In contrast, the production server fails to update its bundle hashes in response to script file modifications and/or changes to the composition of script bundles (even after restarting IIS or recycling the application pool). This suggests that the problem is isolated to the production IIS environment, and is not related to my code changes or Visual Studio configuration.

Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
  • You have checked initially it's not a caching issue? You haven't give much detail to go on, have you confirmed the bundles contain the scripts you expect and there are no duplicates? – Lotok Nov 14 '13 at 12:27
  • I would still check if that's not just some "user error" one. The bundling is not really related to MVC - that's another MS component. I've recently used it with winforms as well. Everything works like a charm. – Agat Nov 14 '13 at 12:35
  • @James: I am happy to provide more detail if you can suggest what I should look for. I am not sure how to check whether it's a caching issue. I have confirmed that the HTTP responses to bundle requests contain the old versions of the scripts (in minified form). Where else should I look and what should I be looking for? – Tim Coulter Nov 14 '13 at 12:36
  • @Agat: I agree, it also worked well for me until now. However, this is not a user error. I've seen for myself that the scripts delivered in response to a bundle request are out of data. More significantly, the request querystring is also not updated when the script content changes. – Tim Coulter Nov 14 '13 at 12:38
  • @TimCoulter What's about your updates (did you do any with binaries)? – Agat Nov 14 '13 at 13:00
  • @TimCoulter Did you edit existing files or replace them with new ones? If you are watching the traffic and seeing it delivering the old files then it won't be a client side caching issue. If it was a `CTRL+F5` would solve it anyway. – Lotok Nov 14 '13 at 13:02
  • @Agat: no binaries. The JavaScript originates as TypeScript and is compiled in Visual Studio before being deployed. I have checked that the compiled .js files are correctly compiled and deployed to the server, but they are not served. – Tim Coulter Nov 14 '13 at 14:45
  • @ James: I edited existing JavaScript files and re-deployed them. I understand that these changes should be automatically detected by the bundling process, resulting in a new file hash being calculated and used as the request querystring parameter ... except that it's not happening. – Tim Coulter Nov 14 '13 at 14:47
  • @Tim Coulter I meant whether you did any updates on any binaries (Assemblies/packages). – Agat Nov 14 '13 at 14:52
  • @Agat: Yes, there have been many changes in the C# and Razor code, but nothing that is obviously related to the bundling process. – Tim Coulter Nov 14 '13 at 14:57
  • @Tim Coulter I do not mean your updates in code, but if you do any updates from Nuget or something else. – Agat Nov 14 '13 at 14:59
  • 1
    Same question: http://stackoverflow.com/questions/12158933/asp-net-bundling-bundle-not-updating-after-included-file-has-changed-returns – niaher May 28 '14 at 09:54

2 Answers2

19

After a lot of searching, I eventually stumbled upon the cause of this problem.

The failure of the server to detect newly deployed changes to JavaScript files was caused by a few similarly-named minified versions of these JavaScript files existing on the server. I assume this behavior is by design, namely that the bundling process gives preference to an existing minified file and ignores an equivalent un-minified file, even if it is newer.

I can't be sure exactly how these few minified files came to be on the server, but I assume they were the result of an experiment involving some alternative form of minification/bundling. In any case, simply deleting them allowed the bundling mechanism to see my deployed script files and everything started working.

Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
  • I had this problem because I installed Web Essentials, then disabled it later down the line—the old minified files were left hanging around, only being used by the Release build. – Jordan Gray Feb 24 '14 at 16:57
  • Had the same problem, I'm happy I found this post! – WIRN Aug 29 '14 at 08:42
  • Easy to fall into this trap if your minified file is not part of your solution and you spend a lot of time in the solution explorer. – cage rattler Jun 05 '15 at 20:02
0

I think there might be an issue with ASP.NET cache dependencies and read only files on disk, can you check if your files end up read only in your deployment environment?

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
  • Thanks for your suggestion. Actually I eventually found the cause of this problem, which I'll document as an answer. – Tim Coulter Nov 15 '13 at 17:47