Skip to content

Instantly share code, notes, and snippets.

@jayli
Created May 10, 2012 02:28
Show Gist options
  • Save jayli/2650596 to your computer and use it in GitHub Desktop.
Save jayli/2650596 to your computer and use it in GitHub Desktop.
delay.php - 延迟输出某个assets文件
<?php
/**
*
* delay.php?f=file.js&t=100
*
* 延时100毫秒加载file.js
*
* */
//得到扩展名
function get_extend($file_name) {
$extend =explode("." , $file_name);
$va=count($extend)-1;
return $extend[$va];
}
/**
* begin
*/
//cdn上存在的各种可能的文件类型
$header = array(
'js' => 'Content-Type: application/x-javascript',
'css' => 'Content-Type: text/css',
'jpg' => 'Content-Type: image/jpg',
'gif' => 'Content-Type: image/gif',
'png' => 'Content-Type: image/png',
'jpeg' => 'Content-Type: image/jpeg',
'swf' => 'Content-Type: application/x-shockwave-flash'
);
$filename = $_GET['f'];
$R_files = file($_GET['f']);
if(empty($type)) {
$type = get_extend($filename);
}
header($header[$type]);
ob_flush();
flush();
sleep($_GET['t']);
//var_dump($R_files);
echo join("\n",$R_files);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment