简体   繁体   中英

Silverstripe requirements combined files CSS and JS

In SS we can do combined files to make run websites faster. But It was a problem when some files is being updated and the are not refreshed into combined file. I must delete the combined file and flush the cache to recreate the file... Is there are a function to redo the creation of the combined file when a CSS file being changed? Like check the date of files?

Example :

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

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

Files aren't being combined when in dev mode. So during development, when files change a lot, make sure to run your site in dev-mode.

You should also require all your files normally. Changed code:

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

When your website is in live mode, the individual files will be replaced with the combined file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM