Yii 什么是;“强制编译”;当你使用更少的时候,你的意思是什么?

Yii 什么是;“强制编译”;当你使用更少的时候,你的意思是什么?,yii,Yii,我有这个: 'components'=>array( 'less'=>array( 'class'=>'ext.less.components.LessCompiler', 'forceCompile'=> true, //YII_DEBUG, // indicates whether to force compiling //'compress'=>false, // indicates whether to compress comp

我有这个:

'components'=>array(
  'less'=>array(
    'class'=>'ext.less.components.LessCompiler',
    'forceCompile'=> true, //YII_DEBUG, // indicates whether to force compiling
    //'compress'=>false, // indicates whether to compress compiled CSS
    //'debug'=>false, // indicates whether to enable compiler debugging mode
    'paths'=>array(
      'less/style.less'=>'css/style.css',
    ),
  ),
如果我启用forceCompile,我的站点速度会非常慢。我可以想象,因为它会在每次加载页面时重新生成css。我的问题是禁用它。如果我禁用它:

  • 我对style.less所做的任何更改都不会反映在浏览器中吗
  • 如果是这样的话,少一点有什么意义?那么它真的不能用于生产吗?还是禁用forceCompile,使其只生成一次
  • 如对forceCompile有任何澄清,将不胜感激


    (是的,我找了所有的人都想得到一个清楚的解释……我能找到的最好的解释是)。

    首先,让我告诉你:

  • less是一种语言,因此一般来说,使用less可以帮助您编写易于维护的css,尽管使用的“语言”语法较少。作为一个常见的例子,您可以在less中定义变量,这些变量根据less文件中的其他语句编译为css值。或者,您可以像在大多数其他支持OOP的语言中一样使用混合、嵌套和继承概念

  • 因此,您可以编写可理解、可读的伪/元css代码,并在编译时转换为实际css


  • 现在是分机:

    即使禁用了
    forceCompile
    ,在style.less中所做的更改也会反映出来,因为扩展名会检查文件是否被修改(LessCompiler.php中的以下几行应该会让您确信这一点):


    因此,
    forceCompile
    将始终编译您在
    路径中指定的文件,您不应在生产中启用它。
    hasChanges
    调用应该处理较少的已修改文件,并编译它们,正如您在上面看到的那样,这是由扩展名自动完成的。

    较少的点,如较少的语言或较少的扩展名?两者兼而有之。扩展实现的更少?你为什么这么问?(我想我没抓住你问题的重点……)少了朗,肯定也在生产中使用。分机是你的选择
    if ($this->forceCompile || $this->hasChanges())
        $this->compileAll();
    
    // ...
    
    /**
     * Returns whether any of files configured to be compiled has changed.
     * @return boolean the result.
     */
    protected function hasChanges() {
        // ...
            $compiled = $this->getLastModified($destination);
        // ...
            $modified = $this->getLastModified($dir);
        // ...
    }
    
    /**
     * Returns the last modified for a specific path.
     * @param string $path the path.
     * @return integer the last modified (as a timestamp).
     */
    protected function getLastModified($path){ 
        //...
    }