Lessons

Minification of JavaScript files to reduce its volume

During minification, the file is modified as follows:

  • Extra characters are removed: spaces, line breaks, semicolons, etc . - The names of functions and variables are replaced with shorter ones where possible.
  • Logical expressions are simplified so that the functionality remains the same.
  • and other optimizations.

All these operations fully preserve the functionality of the code and allow you to reduce the size of files. This is necessary to speed up the download of the file and, therefore, the page.

How to minify files.

Example of minified and regular JavaScript code:

/*Стандартный читаемый JavaScript код*/
function updateLabel(label, resizeElement, position) {
    if(position == 'left') {
        ( label.offset().left + label.outerWidth() < resizeElement.offset().left + resizeElement.outerWidth() ) ? label.removeClass('is-hidden') : label.addClass('is-hidden') ;
    } else {
        ( label.offset().left > resizeElement.offset().left + resizeElement.outerWidth() ) ? label.removeClass('is-hidden') : label.addClass('is-hidden') ;
    }
}
/*Идентичный по функциональности, но минифицированный JavaScript код*/
function updateLabel(e,t,d){"left"==d?e.offset().left+e.outerWidth()<t.offset().left+t.outerWidth()?e.removeClass("is-hidden"):e.addClass("is-hidden"):e.offset().left>t.offset().left+t.outerWidth()?e.removeClass("is-hidden"):e.addClass("is-hidden")}

Tariff plans for working with the service

We use cookies. By continuing to use the site, you agree to the processing of personal data in accordance with privacy policy. I agree