public function cacheAssets(&$files, $key) {
    foreach ($files as $type => $assets) {
      if (empty($assets)) {
        continue; // Skip no assets
      }

      $content = '';
      foreach ($assets as $asset) {
        // Get content from asset file
        $assetContent = file_get_contents($this->path . $asset->path);
        $cssRelPath = preg_replace('/[^\/]+$/', '', $asset->path);

        // Get file content and concatenate
        if ($type === 'scripts') {
          $content .= $assetContent . ";\n";
        }
        else {
          // Rewrite relative URLs used inside stylesheets
          $content .= preg_replace_callback(
              '/url\([\'"]?([^"\')]+)[\'"]?\)/i',
              function ($matches) use ($cssRelPath) {
                  if (preg_match("/^(data:|([a-z0-9]+:)?\/)/i", $matches[1]) === 1) {
                    return $matches[0]; // Not relative, skip
                  }
                  return 'url("../' . $cssRelPath . $matches[1] . '")';
              },
              $assetContent) . "\n";
        }
      }

      self::dirReady("{$this->path}/cachedassets");
      $ext = ($type === 'scripts' ? 'js' : 'css');
      $outputfile = "/cachedassets/{$key}.{$ext}";
      file_put_contents($this->path . $outputfile, $content);
      $files[$type] = array((object) array(
        'path' => $outputfile,
        'version' => ''
      ));
    }
  }
public function cacheAssets(&$files, $key) {
    foreach ($files as $type => $assets) {
      if (empty($assets)) {
        continue; // Skip no assets
      }

      $content = '';
      foreach ($assets as $asset) {
        // Get content from asset file
        $assetContent = file_get_contents($this->path . $asset->path);
        $cssRelPath = preg_replace('/[^\/]+$/', '', $asset->path);

        // Get file content and concatenate
        if ($type === 'scripts') {
          $content .= $assetContent . ";\n";
        }
        else {
          // Rewrite relative URLs used inside stylesheets
          $content .= preg_replace_callback(
              '/url\([\'"]?([^"\')]+)[\'"]?\)/i',
              function ($matches) use ($cssRelPath) {
                  if (preg_match("/^(data:|([a-z0-9]+:)?\/)/i", $matches[1]) === 1) {
                    return $matches[0]; // Not relative, skip
                  }
                  return 'url("../' . $cssRelPath . $matches[1] . '")';
              },
              $assetContent) . "\n";
        }
      }

      self::dirReady("{$this->path}/cachedassets");
      $ext = ($type === 'scripts' ? 'js' : 'css');
      $outputfile = "/cachedassets/{$key}.{$ext}";
      file_put_contents($this->path . $outputfile, $content);
      $files[$type] = array((object) array(
        'path' => $outputfile,
        'version' => ''
      ));
    }
  }
public function cacheAssets ( & $ files , $ key ) { foreach ( $ files as $ type => $ assets ) { if ( empty ( $ assets ) ) { continue ; // Skip no assets } $ content = '' ; foreach ( $ assets as $ asset ) { // Get content from asset file $ assetContent = file_get_contents ( $ this -> path . $ asset -> path ) ; $ cssRelPath = preg_replace ( '/[^\/]+$/' , '' , $ asset -> path ) ; // Get file content and concatenate if ( $ type === 'scripts' ) { $ content .= $ assetContent . ";\n" ; } else { // Rewrite relative URLs used inside stylesheets $ content .= preg_replace_callback ( '/url\([\'"]?([^"\')]+)[\'"]?\)/i' , function ( $ matches ) use ( $ cssRelPath ) { if ( preg_match ( "/^(data:|([a-z0-9]+:)?\/)/i" , $ matches [ 1 ] ) === 1 ) { return $ matches [ 0 ] ; // Not relative, skip } return 'url("../' . $ cssRelPath . $ matches [ 1 ] . '")' ; } , $ assetContent ) . "\n" ; } } self :: dirReady ( "{$this->path}/cachedassets" ) ; $ ext = ( $ type === 'scripts' ? 'js' : 'css' ) ; $ outputfile = "/cachedassets/{$key}.{$ext}" ; file_put_contents ( $ this -> path . $ outputfile , $ content ) ; $ files [ $ type ] = array ( ( object ) array ( 'path' => $ outputfile , 'version' => '' ) ) ; } }
Will concatenate all JavaScrips and Stylesheets into two files in order
to improve page performance.

@param array $files
A set of all the assets required for content to display
@param string $key
Hashed key for cached asset
Will concatenate all JavaScrips and Stylesheets into two files in order to improve page performance .