【问题标题】:Silverstripe requirements combined files CSS and JSSilverstripe 要求结合文件 CSS 和 JS
【发布时间】:2016-08-25 15:20:02
【问题描述】:

在 SS 中,我们可以合并文件以加快网站的运行速度。但是当某些文件正在更新并且没有刷新为组合文件时,这是一个问题。我必须删除组合文件并刷新缓存以重新创建文件......是否有一个功能可以在 CSS 文件被更改时重做组合文件的创建?比如检查文件的日期?

例子:

$stylesheets = array(
    "$themeDir/css/HomePage.css",
    "$themeDir/css/Page.css",
);

Requirements::combine_files('combinedfiles.css', $stylesheets');

【问题讨论】:

    标签: javascript css file silverstripe


    【解决方案1】:

    dev 模式下文件不会被合并。因此,在开发过程中,当文件发生很大变化时,请确保在开发模式下运行您的网站。

    您还应该正常要求所有文件。更改代码:

    $stylesheets = [
        $this->themeDir() . '/css/HomePage.css',
        $this->themeDir() . '/css/Page.css'
    ];
    
    // require the css stylesheet normally
    foreach ($stylesheets as $stylesheet) {
        Requirements::css($stylesheet);
    }
    
    // combine the files. In dev-mode, this has no effect
    Requirements::combine_files('combinedfiles.css', $stylesheets);
    

    当您的网站处于live 模式时,单个文件将被组合文件替换。

    【讨论】:

    • 一点注意,我们必须添加一个条件 -> if (isDev) { do nothing } else { combined_files } 在 live-mode 之后刷新以更新 combine_files
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多