0

I have this code in PHP for combining and compressing css and js files.

$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;

How can I compress and combine css and js files with asp.net

Thanks

2 Answers 2

2

Hanselman has a good post on doing this in .NET.

The latest version of .NET allows you to do this easily via built-in support.

Here's a list of other tools that allow you do this:

Sign up to request clarification or add additional context in comments.

1 Comment

Good roundup of available tools
1

I have had an excellent experience with Combres.

It's very easy to set up and haven't had any major issues with it in the last 2 years.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.