Forums de discussion

How to debug Javascript Minify

thumbnail
Javier Solana, modifié il y a 6 années.

How to debug Javascript Minify

Junior Member Publications: 59 Date d'inscription: 26/06/14 Publications récentes
Hi,

we are facing some problems when deploying a portlet in production.

The $( document ).ready(function() { ... }); in Javascript file is not being executed. No error anywhere...

I think it is due to the Javascript Minify in Liferay, but I need help to debug the problem, since no error appears anywhere.

Locally, with Eclipse, everything works perfectly.

Thanks in advance
thumbnail
David H Nebinger, modifié il y a 6 années.

RE: How to debug Javascript Minify

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
You should not be using the $ alias for the javascript library. Too easy to end up with a namespace collision. Stick with the real name whether it is jquery or aui or ... and avoid the $.










Come meet me at the 2017 LSNA!
thumbnail
Javier Solana, modifié il y a 6 années.

RE: How to debug Javascript Minify

Junior Member Publications: 59 Date d'inscription: 26/06/14 Publications récentes
David H Nebinger:
You should not be using the $ alias for the javascript library. Too easy to end up with a namespace collision. Stick with the real name whether it is jquery or aui or ... and avoid the $.
Come meet me at the 2017 LSNA!


Thanks David for the response, but that is not my problem, $ and jQuery is exactly the same in my environment:

> $ === jQuery
true
thumbnail
Amos Fong, modifié il y a 6 années.

RE: How to debug Javascript Minify

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
You could disabling it to see if it's really your issue. See https://web.liferay.com/community/forums/-/message_boards/message/25412043
thumbnail
Javier Solana, modifié il y a 6 années.

RE: How to debug Javascript Minify

Junior Member Publications: 59 Date d'inscription: 26/06/14 Publications récentes
It was a matter of how a part of the code was being minified. I was using setInterval for creating an animtaion effect:

var id = setInterval(frame, 10);
		function frame() {
		      if (barCompleted[0]&&barCompleted[1]&&barCompleted[2]&&barCompleted[3]&&barCompleted[4]&&barCompleted[5]&&barCompleted[6]) {
		          clearInterval(id);
		      } else {
		    	  for (var i = 0; i < pillars.length; i++) {
		    		  $circle = $('#svg_'+pillars[i]+' #bar_'+pillars[i]);
					  myTimer = document.getElementById("timer_"+pillars[i]);
					  
					  if(showValue >= val[i]){
						  barCompleted[i]=true;
						  myTimer.textContent = val[i];
					  }else{
						  $circle.css({ strokeDashoffset: ((100-showValue)/100)*c});
						  myTimer.textContent = showValue;
						  showValue++;
					  }
		    	  }
		      }
		  }


I juist removed this effect and everything works perfectly, since I didn't manage to understand why the minifying process didn't like this part.