Monday, November 3, 2014

ASP.NET: Force client to update javascript files after each new build


Problem

How to force a client to update cached javascript files after each new build

Solution

Add build number property to your page class

Protected ReadOnly Property CurrentVersion() As Integer
        Get
            Return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build
        End Get
End Property

And update script source to utilize the build number property


<script src="Script/Functions.js?v=<%= CurrentVersion%>" type="text/javascript"></script>


After each new build script source url is changed so browser will update javascript-file to the cache


No comments:

Post a Comment