Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET bundle cache not clearing after modifications

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.

like image 417
Tim Coulter Avatar asked Nov 14 '13 12:11

Tim Coulter


1 Answers

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.

like image 108
Tim Coulter Avatar answered Nov 03 '22 21:11

Tim Coulter