<分区>
我在审核我的网站时发现了这条关于 将外部 javascript 合并为一个。
我怀疑做这样的事情是否是一个好习惯:
function js($which) {
$output = "";
switch($which) {
case "mainsec1";
$output .= file_get_contents("js/main.js");
$output .= file_get_contents("js/sec1.js");
break;
}
// And so on with the other cases
echo $output;
}
然后从 html 我会做类似的事情:
<script src="controller/js/mainsec1"></script>
这样我可以减少 http 请求的数量,但仍然可以保留不同的文件以用于避免冗余的维护问题。
你怎么看?