Reputation: 415
I need to bundle my .js files and lib files in my Mvc project, i am looking for version number for bundle, as my browser need to reload all .js and .lib files when ever new version is added or build is pushed to dev/testing/prod environments.
Upvotes: 0
Views: 41
Reputation: 76577
Bundling in ASP.NET MVC already has a built-in mechanism for handling these type of cache-busting scenarios for release builds as per the "Bundle Caching" section of this documentation :
As long as the bundle doesn't change, the ASP.NET application will request the AllMyScripts bundle using this token. If any file in the bundle changes, the ASP.NET optimization framework will generate a new token, guaranteeing that browser requests for the bundle will get the latest bundle.
This features uses a token within the querystring called v
to indicate current "version" of the bundle that looks like :
v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81
This functions as a unique identifier for the particular build and as long as nothing in the bundle was changed, it will continue to use it, otherwise a new one would be generated to "bust" any existing caching.
For Non-Release Builds
If you needed to handle this in non-release builds, then I believe you could set the EnableOptimizations
property to true
to always handle this :
BundleTable.EnableOptimizations = true;
Upvotes: 1