0

I've used Bundleconfig.cs to bundle my javascript files as follows:

bundles.Add(new ScriptBundle("~/bundles/resultscripts").Include(
             "~/Scripts/spectrum.js",
              "~/Scripts/notify.js",
              "~/Scripts/spin.min.js"));
   BundleTable.EnableOptimizations = true;

Then in my .cshtml file, I've got the following:

@Scripts.Render("~/bundles/resultscripts");

This renders in chrome as:

<script src="/bundles/resultscripts?v=3ozhz2yni5K8Is0g9QoONh_MkoivcBzooVIUD-a0Ngw1"></script>

Then I have the following under system.web in my Web.config (not sure how much this matters):

<compilation debug="true" targetFramework="4.5.2" />

This is good because it allows bundle versioning. However, some of my javascript doesn't seem to be firing, and when in Chrome, I can now no longer place breakpoints in my individual javascript files. Or to be more clear, I can't find notify.js for example. I'm guessing this is because the bundle is being minified.

If I set BundleTable.EnableOptimizations = false; my javascript files render but are no longer versioned.

I was wondering if anyone could point me in the right direction so that I can find the individual files when bundling with versions?

I checked out this: Script bundles not rendering individual files in debug, and am using the same syntax, but my files are not getting rendered individually.

kickinchicken
  • 1,281
  • 4
  • 18
  • 40
  • After bundling, you cannot debug the JavaScript codes easily. It is an expected behavior. What is your concern? Do you see any script error? – Win Jul 06 '17 at 19:45
  • Thanks for responding so quickly: I should have been more clear: My concern is that when I have BundleTable.EnableOptimizations set to true, some of my scripts aren't firing. When I have it set to false, everything works fine. The debugging issue is something I can live with. – kickinchicken Jul 06 '17 at 19:53

2 Answers2

1

I hope below statement will be helpful for you:

when we are not in a debug compilation and have not turned off the EnableOptimizations feature, MVC will combine those files in our bundles, compress (minify) them and output only a single script tag

Source : https://stackoverflow.com/a/21271866/3397630

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12
0

Could you use .* and see any different?

bundles.Add(new ScriptBundle("~/bundles/resultscripts").Include(
   "~/Scripts/spectrum.*",
   "~/Scripts/notify.*",
   "~/Scripts/spin.*"));

BundleTable.EnableOptimizations = true;
Win
  • 61,100
  • 13
  • 102
  • 181
  • Do you have spectrum.min.js and notify.min.js files? – Win Jul 06 '17 at 20:38
  • If so, could you add them as `.Include("~/Scripts/spectrum.min.js","~/Scripts/notify.min.js","~/Scripts/spin.min.min.js"));` – Win Jul 06 '17 at 20:45
  • I'm not sure if I'm missing something... How is that different than what I have? – kickinchicken Jul 06 '17 at 20:52
  • If it sees *.min file, it uses *.min and bundle them. Otherwise, it becomes two steps - minify and then bundle. Sometimes, minifying could mess up the files unintentionally. – Win Jul 06 '17 at 20:56
  • So... I have more information: It turns out that the offending files were .css files that I had referenced in Syles.Render blocks. When I took these out, things seemed to work fine. Any idea of why this would be happening? – kickinchicken Jul 10 '17 at 13:30
  • Style.Render is where a bundle is rendered to browser. Some CSS files are sensitive to resource path. For that case you cannot bundle them. *For example, Kendo UI in my sample code [Kendo](https://github.com/WinLwinOoNet/AspNetMvcActiveDirectoryOwin/blob/master/src/Presentation/AspNetMvcActiveDirectoryOwin.Web/App_Start/BundleConfig.cs#L30) and [Bundle](https://github.com/WinLwinOoNet/AspNetMvcActiveDirectoryOwin/blob/master/src/Presentation/AspNetMvcActiveDirectoryOwin.Web/Views/Shared/_Layout.cshtml#L8).* – Win Jul 10 '17 at 20:13
  • Thanks guys. Stay tuned. I'll post my solution soon. – kickinchicken Jul 12 '17 at 13:02