What are some potential pitfalls of combining CSS and JS files in PHP to save on requests?

Combining CSS and JS files in PHP can lead to slower load times if the files are large, as the browser will have to download the entire combined file even if only one of the resources is needed. To mitigate this issue, you can dynamically generate separate CSS and JS files based on the requested resources, reducing the overall file size and improving load times.

// Example PHP code snippet to dynamically generate separate CSS and JS files

$css_files = array(
    'style.css',
    'custom.css'
);

$js_files = array(
    'script.js',
    'custom.js'
);

if(isset($_GET['css'])) {
    header('Content-type: text/css');
    foreach($css_files as $file) {
        readfile($file);
    }
    exit;
}

if(isset($_GET['js'])) {
    header('Content-type: application/javascript');
    foreach($js_files as $file) {
        readfile($file);
    }
    exit;
}