Removing unused JavaScript

Why do I need to delete unused JavaScript code?

Sites are constantly updated, new features are added, and old ones are removed. Often, unused code remains in JavaScript files. It clogs them. The larger your JavaScript files are, and the more extra code they contain, the more difficult it is for programmers to read and modify them. This affects the speed of work.

Unused code slows down the browser. This problem is especially relevant for mobile device users. By cleaning JavaScript files, you speed up the programmer’s work as he spends most of his time reading code. Clean code is easier to understand. The probability of error is reduced.

How effective is removing unused JavScript?

The older the site, the more garbage it contains.

The average acceleration is 0.1-0.2 seconds. Considering that the page should load faster than 2 seconds, this is a 5-10% increase in speed.

How to use?

Article instruction.

Video instruction: VK video, Youtube, Zen, [Rutube](https://rutube.ru/video/bea005ee519dc54f7bac0ce1635e5319 /).

In general, the procedure for working with the tool consists of 4 simple steps:

  • Scanning site pages in the tool. Takes about 15 minutes. Do not forget to disable the file grouping feature, if any.
  • Transfer of files generated by the service to your development site. Just copy them with the replacement to the root folder of your site. It will take 5 minutes. If you have your own JavaScript file management system, then the files will have to be replaced manually.
  • Testing and editing. You will need to open the pages and check if any function has stopped working. The lead time is 2-4 hours per sample page. For example, if you have an online store, it is enough to test one product card so that the changes apply immediately to all the others.
  • Removal of beacons and commented functions. Actually, this is the removal of unnecessary code. It takes about 10-20 minutes for 1 JavaScript file.

As a result, a few days of work will speed up your site by tens of percent.

Tips:

  • Disable code minification before scanning.
  • Carry out all manipulations in a test copy of the site.
  • Start with the main files of your template, and then move on to plugins and system files.
  • Use a version control system like git or SVN. So you will control the change of each line and, if anything, you will be able to return everything back.

How to work with the tool correctly and not remove anything superfluous?

Most of the JavaScript code of the page is executed in response to user actions. For example, if a function is executed when clicking on an element, it will be commented out. This is because our tool does not simulate user actions.

We have provided a solution for this situation. In the files provided by our tool, we comment on unused functions and place beacons. If any function was commented out by mistake, but will be called in the code, then you will see a message in the browser console stating that the function is being used. After that, all you have to do is find the right line using the unique beacon code and uncomment the function.

Are there any analogues of our tool?

No.

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