ASP.NET 4.5 Debug Mode Consolidation - Deprecated Resources

Is there any way to make the ASP.NET 4.5 Bundling feature set generate a GUID as part of the request when starting in debug mode (for example, the connection is disconnected).

The problem is that when created locally, script / CSS files are generated as follows:

<script type="text/javascript" src="/Content/Scripts/myscript.js" /> 

So, if I modify this file, I need to do a hard update (sometimes several times) to get a file that will be cleaned by the browser - annoying.

Is it possible to make it look like this:

 <script type="text/javascript" src="/Content/Scripts/myscript.js?v=x" /> 

Where x is the GUID (for example, always unique).

Ideas?

I am on ASP.NET MVC 4.

+4
source share
3 answers

Until the NuGet package is fixed according to the other answer above, for now I have finished using the same shell code that I did for the NuGet beta package:

 private static IHtmlString JsUnbundled(this HtmlHelper htmlHelper, string bundlePath) { var jsBuilder = new StringBuilder(); foreach (var file in BundleResolver.Current.GetBundleContents(bundlePath)) { var tagBuilder = new TagBuilder("script"); tagBuilder.Attributes["src"] = file.AddCacheKey(); // add GUID tagBuilder.Attributes["type"] = "text/javascript"; jsBuilder.AppendLine(tagBuilder.ToString()); } return MvcHtmlString.Create(jsBuilder.ToString()); } 

Then I have another HTML helper that checks if it is being debugged, and then uses the above - otherwises uses Scripts.Render .

Obviously, this does not hash the file β€” it will ALWAYS request the file. But I am not against it, as it is only for debugging.

+4
source

We are not currently viewing the contents of files in debug mode, but we can add this feature.

I filed it as a problem on codeplex here .

+1
source

Try HashCache: https://github.com/kemmis/System.Web.Optimization.HashCache

Run the ApplyHashCache () extension method on the BundlesCollection instance after all packages have been added to the collection.

 BundleTable.Bundles.ApplyHashCache(); 

This will add content hashes to the script / style tags displayed in debug mode.

0
source

Source: https://habr.com/ru/post/1442879/


All Articles