Javascript not loaded properly on first time

41 views Asked by At

In my MVC application ,i made changes in JS file and when load the application for the very first time it is not working as per the new code but it's working as per the old code . So i think this is the problem of versioning of JS. We use bundles of JS in our application

bundles.Add(new ScriptBundle("~/bundles/ClientSetup").Include("~/Scripts/Views/Admin/ClientSetup.js"
                                                                       ,"~/Scripts/Views/Admin/IndicesSetup.js"
                                                                        ,"~/Scripts/Views/Admin/PreferencesSetup.js"));

We have to do hard refresh than it is working as expected. So how to achieve versioning here any idea?

1

There are 1 answers

0
alpha-before-beta On

Depending on the version of .NET and MVC you are using, I recommend the WebHelpers.Mvc5 nuget package. It contains an AddVersion() extension method.

https://www.nuget.org/packages/WebHelpers.Mvc5/

https://github.com/c0shea/WebHelpers.Mvc5

Example

bundles.Add(new ScriptBundle("~/bundles/ClientSetup").Include("~/Scripts/Views/Admin/ClientSetup.js"
                                                                       ,"~/Scripts/Views/Admin/IndicesSetup.js"
                                                                        ,"~/Scripts/Views/Admin/PreferencesSetup.js").AddVersion());