Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Alzee Inc
5,894 PointsNo white space in javascript code?
On website, I often see that their code is written without backspace, whitespace, etc. Like this for example:
function(t){var e={},s={mode:"horizontal",slideSelector:"",infiniteLoop:!0,hideControlOnEnd:!1,speed:500,easing:null,slideMargin:0,startSlide:0,randomStart:!1,captions:!1,ticker:!1,tickerHover:!1,adaptiveHeight:!1,adaptiveHeightSpeed:500,video:!1,useCSS:!0,preloadImages:"visible",responsive:!0,slideZIndex:50,touchEnabled:!0,swipeThreshold:50,oneToOneTouch:!0,preventDefaultSwipeX:!0,preventDefaultSwipeY:!1,pager:!0,pagerType:"full",pagerShortSeparator:" /
Instead of writing it like this:
;(function($){
var plugin = {};
var defaults = {
// GENERAL
mode: 'horizontal',
slideSelector: '',
infiniteLoop: true,
hideControlOnEnd: false,
speed: 500,
Is there a reason for that? (Also, this was just a sample from a code, what is written doesn't matter, just how). Thanks :)!
1 Answer
Michael Hess
24,512 PointsHi Alzee Inc,
Yes, there is a reason, this is a practice known as minifying. Minified javascript files are ideal for production environments since they typically reduce the size of the file by 30-90% -- which results in a page being loaded faster. Most of the filesize reduction is achieved by removing comments and extra whitespace characters that are not needed by web browsers or visitors.
Here is a link to a site that will minify JavaScript: jscompress
If you have any further questions feel free to ask! Hope this helps!