protected function combineScriptFiles($type = self::POS_HEAD)
	{
		// Check the need for combination
		if (!isset($this->scriptFiles[$type]) || count($this->scriptFiles[$type]) < 2)
			return;

		$scriptFiles = array();
		$toBeCombined = array();
		foreach ($this->scriptFiles[$type] as $url)
		{
			$file = $this->getLocalPath($url);

			if ($file === false)
				$scriptFiles[$url] = $url;
			else
				$toBeCombined[$url] = $file;
		}

		if (count($toBeCombined) === 1)
		{
			$url = key($toBeCombined);
			$scriptFiles[$url] = $url;
		}
		else if (count($toBeCombined) > 1)
		{
			// get unique combined filename
			$fname = $this->getCombinedFileName($this->scriptFileName, array_values($toBeCombined), $type);
			$fpath = Yii::app()->assetManager->getBasePath() . DIRECTORY_SEPARATOR . $fname;

			// check exists file
			if ($valid = file_exists($fpath))
			{
				//$cache = Yii::app()->cache->get('combineCss' . md5($fpath) . md5($fname));
				//if ($cache === false)
				//	$valid = false;

				$mtime = filemtime($fpath);
				foreach ($toBeCombined as $file)
				{
					if ($mtime < filemtime($file))
					{
						$valid = false;
						break;
					}
				}
			}

			// re-generate the file
			if (!$valid)
			{
				$fileBuffer = '';
				foreach ($toBeCombined as $url => $file)
				{
					$contents = file_get_contents($file) . ';';
					if ($contents)
					{
						if ($this->optimizeScriptFiles && strpos($file, '.min.') === false && strpos($file, '.pack.') === false)
						{
							$contents = $this->optimizeScriptCode($contents);
						}
						$fileBuffer .= (($this->optimizeScriptFiles == true) ? preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents) : $contents);
					}
				}
				file_put_contents($fpath, $fileBuffer);
				//Yii::app()->cache->set('combineCss' . md5($fpath) . md5($fname), true);
			}
			// add the combined file into scriptFiles
			$url = Yii::app()->assetManager->getBaseRelUrl() . '/' . $fname;
			$scriptFiles[$url] = $url;
		}
		// use new scriptFiles list replace old ones
		$this->scriptFiles[$type] = $scriptFiles;
	}