MVC4 StyleBundle: Can you add a cache-busting query string in Debug mode?

后端 未结 6 1528
不思量自难忘°
不思量自难忘° 2020-12-13 06:16

I\'ve got an MVC application and I\'m using the StyleBundle class for rendering out CSS files like this:

bundles.Add(new StyleBundle(\"~/bundles         


        
6条回答
  •  轮回少年
    2020-12-13 06:29

    This library can add the cache-busting hash to your bundle files in debug mode, as well as a few other cache-busting things: https://github.com/kemmis/System.Web.Optimization.HashCache

    You can apply HashCache to all bundles in a BundlesCollection

    Execute the ApplyHashCache() extension method on the BundlesCollection Instance after all bundles have been added to the collection.

    BundleTable.Bundles.ApplyHashCache();
    

    Or you can apply HashCache to a single Bundle

    Create an instance of the HashCacheTransform and add it to the bundle instance you want to apply HashCache to.

    var myBundle = new ScriptBundle("~/bundle_virtual_path").Include("~/scripts/jsfile.js");
    myBundle.Transforms.Add(new HashCacheTransform());
    

提交回复
热议问题