The fewer scripts at each stage of loading, the higher its speed. Scripts are the hardest part of pages to optimize for. There are scripts that depend on their location (for example, advertising from Google AdWords). Therefore, the default optimization makes minimal changes. Many other optimizing plugins can “break” the scripts.
The most efficient way to optimize scripts is to delay their loading. But scripts are needed to display the page correctly. Therefore, they are divided into 3 groups:
This includes everything that needs to be loaded before the main content of the page. This is usually empty.
Everything that can be loaded after the main content of the page with a delay. Usually, all the main scripts of the site are here.
Anything that can be loaded even later and does not affect the main rendering of the page. This includes, for example, scripts for tracking, advertising, social networks, etc.
Script optimization (JS)#
- Delayed loading
By default, the non-critical and special group’s load latency times are set for the greatest compatibility and the best performance. For specific sites, these values can be empirically reduced.
By analogy with styles (CSS), it reduces the number of requests to the server, thereby reducing the page load time. But from experience, due to scripts being generally loaded on hold, then this does not give a tangible increase in the rating and the likelihood of disrupting their work increases. GTMetrix shows the number of requests, and by enabling this mode, you can try to increase the score on it.
Reducing the size of scripts by removing extra spaces and line breaks.
The solution has been tested with the most popular plugins, does not “break” advertising scripts, analytics scripts, and video frames. According to statistics, about 20% of sites require additional configuration, most of which, of course, are related to scripts.