Obfuscating JavaScript
Posted on May 19, 2017

I’m now obfuscating my JS code and linking to these files as part of inputforcolor’s new commercial expansion.
This essentially means that I can demonstrate ifc webtemplates online whilst making it a little more difficult for viewers to take the code and adapt it. In this sense ‘obfuscation’ is similar to protecting copyright, but the process also makes the code smaller and therefore slightly faster as well.

To understand the process here is a simple Javascript file which operates the latest version of ifc’s single-page parallax webTemplate

<CODE>
$(document).ready(function () {
// toggle smartphone menu
$(‘.navIcon’).click(function () {
$(‘.navBar’).slideToggle();
});
$(window).bind(‘resize’, function () {
if ($(‘.navIcon’).css(‘display’) == “none”) {
$(‘.navBar’).show();
} else {
$(‘.navBar’).hide();
}
});
$(‘.navBar li a’).click(function (event) {
event.preventDefault();
var sectionId = $(this).attr(‘href’);
var distanceFromTop = $(sectionId).offset().top;
$(‘html, body’).animate({
scrollTop: distanceFromTop
}, 2000);
if ($(‘.navIcon’).css(‘display’) == ‘block’) {
$(‘.navBar’).slideUp();
}
});
$(window).scroll(function () {
$(‘.outerDiv’).each(function () {
var distanceFromTop = $(this).offset().top;
if (window.scrollY >= (distanceFromTop + 80)) {
$(this).addClass(‘fixPoint’);
} else {
$(this).removeClass(‘fixPoint’);
}
})
})
})

 

and here is the same code after obfuscation

<CODE>
var _$_cb62=[“slideToggle”,”.navBar”,”click”,”.navIcon”,”resize”,”display”,”css”,”none”,”show”,”hide”,”bind”,
“preventDefault”,”href”,”attr”,”top”,”offset”,”animate”,”html, body”,”block”,”slideUp”,”.navBar li a”,”scrollY”,
“fixPoint”,”addClass”,”removeClass”,”each”,”.outerDiv”,”scroll”,”ready”];
$(document)[_$_cb62[28]](function(){$(_$_cb62[3])[_$_cb62[2]](function(){$(_$_cb62[1])[_$_cb62[0]]()});$(window)[_$_cb62[10]](_$_cb62[4],function(){if($(_$_cb62[3])[_$_cb62[6]](_$_cb62[5])== _$_cb62[7]){$(_$_cb62[1])[_$_cb62[8]]()}else {$(_$_cb62[1])[_$_cb62[9]]()}});$(_$_cb62[20])[_$_cb62[2]](function(_0xF609){_0xF609[_$_cb62[11]]();var _0xF632=$(this)[_$_cb62[13]](_$_cb62[12]);var _0xF5E0=$(_0xF632)[_$_cb62[15]]()[_$_cb62[14]];$(_$_cb62[17])[_$_cb62[16]]({scrollTop:_0xF5E0},2000);if($(_$_cb62[3])[_$_cb62[6]](_$_cb62[5])== _$_cb62[18]){$(_$_cb62[1])[_$_cb62[19]]()}});$(window)[_$_cb62[27]](function(){$(_$_cb62[26])[_$_cb62[25]](function(){var _0xF5E0=$(this)[_$_cb62[15]]()[_$_cb62[14]];if(window[_$_cb62[21]]>= (_0xF5E0+ 80)){$(this)[_$_cb62[23]](_$_cb62[22])}else {$(this)[_$_cb62[24]](_$_cb62[22])}})})})

 

Neither easy to read nor steal / adapt!! >B )</>