I just finished patching some Dev and Test servers to Nov2017CU (SharePoint 2013). Since then, any solutions that were using JS injection from Site Assets were not updating. I’d make a change to the file, the library reflects that I made the change, but when I attempted to load the page accessing the js file, the changes were not reflected. Hard refreshes and full cache cleans were not affecting it. If I closed and reopened my editor (VSCode) my changes were gone. When I looked at the version history, the current version didn’t have my changes, but the previous version did. If I tried to revert to that version, it didn’t take (still showed the previous version of the file).
Then things got really weird. I deleted the entire file from the library and reset IIS (heck, I even rebooted the server at one time). It somehow still loaded the file. The file is no longer in the library, but the server is still serving it up to the browser. I confirmed it is not getting the file from another location as the Dev tools are showing the file is located in the Asset Library the file was deleted from. Even users who have never accessed the site before were still getting that file in their browser.
So I put out the call for help to a couple of forums and Trevor responded. Asked if we had the blob cache enabled. What is the blob cache you ask? Good question. In a nutshell, the blob cache is SharePoint’s way of saving calls to the database (slow) and instead putting the files on the server’s file system (fast). So files that are large or called often can be stored there for faster response to users. You can read more on the blob cache here. So getting back to the problem at hand, if you don’t know for sure if you have blob cache enabled or not, you need to check the web.config of your SharePoint web application. Once you have opened it up, do a search for “BlobCache location”. This will take you to the entry for the blob cache:
Scroll all the way over to check the enabled property
To confirm this was the issue I went into the blob cache location and found the site I was looking for (note, the site collections are by guid so you will have to go digging). Sure enough, when I found the location my files were saved in, there was the file I had deleted from SharePoint. Because this was here, even though the site no longer contained the file, it was still being served from the file system.
BTW: The SharePoint patching might have caused this or it could have been just a coincidence, but the root problem was the blob cache.
So SharePoint allows you to flush the blob cache. In SharePoint 2010 you could do it from the site collection or using stsadm. Instructions can be found here. However, for SharePoint 2013 and 2016 you are going to have to use PowerShell. The commands you want are:
$spWebApp = Get-SPWebApplication <Web APP URL> [Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($spWebApp)
There is no need to reset IIS for this. The change is immediate. Another thing, is don’t get concerned if you still see the files on the file system. They don’t get deleted. The cache once cleared just means that SharePoint won’t look there and hopefully once it starts looking there again, will store the updated versions of your files and not get stuck at the old version like it did in this case.
The Resolution Part 2
Planning ahead you may wish to look at adding query strings to the URL of your script tag. For example:
Each time you update the file it forces the client to go looking for a newer version of the file. So if you update and change the tag to version=1.0.2, your browser is going to say, well I only have 1.0.1 so I need to ask for a newer version. In theory this will allow it to get the latest version. Thanks to Chris Romp and Gautam Sheth for more information on this.
Again, big thanks to Trevor for the assist.
Thanks for reading!!
Is it necessary to run the ‘flush the blob cache’ PowerShell cmdlets on each server, or will running this from one server clear on all servers?
Great question. You won’t have to flush all servers. The reason being is you are actually flushing the Web App itself and not a local cache on a server. The command I provide will affect all site collections within a web app and is server agnostic.
Thanks for the tip. Experienced same issue and you saved me a lot of time.
You’re very welcome Khurram. Glad I could help.