You would use apache to redirect all requests to a php file, passing the actual file requested as a url parameter, record the request then serve the file.
.htaccess
RewriteCond %{REQUEST_FILENAME} \.(js|css)$
RewriteRule ^(.*)$ request.php?request=$1 [L,QSA]
where request.php
is the php file that is to record the request and js|css
is a |
separated list of extensions you want to redirect.
then to serve the file with php:
header("Content-type: text/javascript");
or
header("Content-type: text/css");
followed by
echo file_get_contents($_GET['request']);
Also, importantly, do not forget to validate the requested file.
Note There may be additional helpful or required headers like content-length, cache-control and pragma. You will need to evaluate your exact needs and work with them accordingly.
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Length: ".filesize($_GET['request']));