Example of php merging js requests
- 2020-11-03 22:04:09
- OfStack
Look at the code for a small example :php merges js requests
// Save the page as js.php
// Foreground request example http://localhost/js.php?f=1,2
// request 1.js,2.js Two files
<?PHP
header("Content-Type:application/x-javascript");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: max-age=".(86400*30));
header("Expires: " .gmdate("D, d M Y H:i:s",time()+86400*30). " GMT");
if($_GET['f'])
{
$url = parse_url($_SERVER['REQUEST_URI']);
$arr_f = array_unique(explode(',',preg_replace("/\.+\//",'',$_GET['f'])));
foreach($arr_f as $v)
{
if(!empty($v))
{
include('./'.$v.'.js');
echo "\n";
}
}
}
?>