What are the best practices for optimizing resource usage when implementing JavaScript features in PHP applications?

When implementing JavaScript features in PHP applications, it's important to optimize resource usage to ensure efficient performance. One way to achieve this is by minimizing the amount of JavaScript code loaded and executed on the client-side. This can be done by only including necessary scripts, using asynchronous loading where possible, and leveraging browser caching.

// Example of including necessary JavaScript files with proper caching headers
$js_files = array(
    'script1.js',
    'script2.js',
    'script3.js'
);

foreach ($js_files as $file) {
    echo '<script src="' . $file . '" defer></script>';
}