I have a small SharePoint project which integrates into a larger SharePoint project. My project has several javascript files and images (via CSS). Whenever I update the app (javascript or images or both), I need to explicitly do a Ctrl + F5 (force refresh) to get the latest version. Users are seeing old data as it is being cached. This application is being used by hundreds of users and I can’t tell everyone of them to do a Ctrl + F5.
How do I disable caching completely for my project?
You could create a server/user control for script/image/css references that wraps the actual html. The control would add a random query string to each of your script/css/image references every time a user requests the page. Your reference would be like:
This would cause the browser to reload the file each time.
However, why would you want to remove caching as that improves load time of pages for your users? You could just as easily use the example that I have and instead of generating a random guid it would generate a guid based on a hash of the current file. That way it would only force the user to update the file if it actually changed. Or, even better, SharePoint already has the
SPUtility.MakeBrowserCacheSafeLayoutsUrlwhich you can use to create a url that will be cached correctly. Here is an exampleHtml in master page (RelativeUrl is under “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS”)
Server Control