MVC4: After bundling the JS is not working properly but without bundling the functionality is working fine

27 Views Asked by At

MVC4: After bundling the ViewModel JS is not working properly but without bundling the functionality is working fine

  1. How to compare the JS libraries loaded in the webpage without bundling and after bundling
  2. We are using jq2.1.3 & Knockout.js 3.4.0 not sure if there are any known issues against this library when bundled
  3. using System.Web.Optimization; (v1.1.3) using BundleTransformer.Core.Transformers; 1.9.34 using BundleTransformer.Yui.Minifiers;
  4. Code snippet - If Condition works fine irrespective of bundling but currText is coming as undefined when bundled. Actually the UI has to render both the staticText + currText but somehow it is not rendering the staticText
                        if (condition.ms() && serverData.currentTransaction.effectiveDate >= constants.ProductVersionDate.pd3) {
                            var currText = obj.model.model.wdng._latestvalue;                   
                            obj.model.model.wdng._latestvalue= obj.model.model.statictext+ currText;

Any help or directions will be much helpful .

Edit: I just found that in my solution after bundling is enabled. knockout-3.4.0.js this library is called.. where as without bundling knockout.debug.3.4.0.js this library is called.

I made sure to call knockout.debug.3.4.0.js irrespective of the bundling configuration and that helped.

wdng._latestValue is not being fetched while using the Knockout-3.4.0.js

Not sure why this discrepancy between the same version of KO works fine on a debug library and does not work fine on a normal one.

https://stackoverflow.com/users/2425942/mkougiouris

1

There are 1 best solutions below

3
MKougiouris On

Some years ago while using a knockout/jquery/mvcBundler setup,i would often find 3rd party libraries, or jquery widgets that would some times have issue when optimized, due to the parsing and processing. I was able to identify those by checking on my js network requests for all feteched javascript bundles, and copied the output to a js verifier. Allthought scrumbled, the code shoud be able to be validaded by online js validators for brackets checkings etc.

On a project having at least 45 js libraries here and there served on the layout of our mvc pipeline we had like 3-4 of those that had broken the ooptimized builds, some where resolved by just updating to different package versions cause quite a lot of them where too old, but for 2 of those i remember to copying the original source code to a new text, re-writing the offending line numbers to be more easy for the parser to work with and then creating by hand a minified version from an online minifier and had that one served from the bundler ( by including the min.js, instead of the actual one for release mode to resolve the issue.

EDIT: Ok then you can either a) update knockout to 3.5.2 ( i think, or the general latest ) b) use online js validators and js minifiers to check on how they would process the existing debug.js and .js files, and see which comes up with invalid js syntax after minifiyng it