Remove some unnecessary JS code from the site

Started by arthyk, Nov 08, 2022, 08:47 AM

Previous topic - Next topic

arthykTopic starter

There is a fairly developed site that I "inherited" from my brother and which I use in the same way, but in a truncated version. There are a lot of redundant JS - scripts with data, most of which are loaded from a file on various pages. I have already removed some of the pages as unnecessary, but those that I use have redundant functionality. The question is: is it possible to remove unnecessary code and data from the js file (in fact ~ 80%) and is it possible to automatically detect this "ballast" code, possibly slowing down the loading of the site?
  •  

Akisingh

There are two ways to delete unused CSS and JS files when loading a page in the browser. The first option is to use premium plugins such as WP Rocket, and the second option is to use a free plugin.

Unlike CSS, removing JS using the WP Rocket plugin is not possible. But, you can enable the "Load Deferred JavaScript" and "Defer JavaScript Execution" options in the "File Optimization > JavaScript Files" section. This will delay both internal and external code and eliminate problems with blocking JavaScript rendering.
  •