php - asp.net合并压缩css、js文件

标签 php asp.net css

我在 PHP 中有这段代码,用于组合和压缩 css 和 js 文件。

$css = '';
$files = explode(',',$_SERVER['QUERY_STRING']);
if( 'css' == $files[0] ){
    $type = 'css';
    $root = 'css/';
}else if( 'javascript' == $files[0] ){
    $type = 'js';
    $root = 'js/';
}
header("Content-type: text/$files[0]");
    ob_start("compress");
    function compress($buffer) {
    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*\/!', '', $buffer);
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
    return $buffer;
    }
if(sizeof($files))
{
  foreach($files as $file)
  {
    $css.= (is_file($root.$file.'.' . $type) ? file_get_contents($root.$file.'.' . $type) : '');
  }
}
echo $css;

如何用asp.net压缩合并css和js文件

谢谢

最佳答案

Hanselman 有一个 good post关于在 .NET 中执行此操作。

最新版本的 .NET 允许您通过 built-in support 轻松完成此操作.

以下是允许您执行此操作的其他工具列表:

关于php - asp.net合并压缩css、js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10773884/

相关文章:

php - 根据条件从数据库中的 2 个表中选择数据 CakePHP

PHP 单例 : not holding instance

asp.net - 通过用户复制/粘贴aspx .net 4.0创建的页面上显示的奇怪字符

javascript - 当 td 类为多个时显示/隐藏选择选项

javascript - 在 ReactJS 中使用主题

php - 如何计算和限制表单提交?

php/mysqli : should I free_result before I return?

c# - "Errors During Preprocessing"在 ASP.NET 性能计数器中非零

asp.net - 检测 VB.Net 中数字的文化,即小数点/千位分隔符的句点或逗号

html - 简单的 HTML/CSS 定位问题