NewbieSSProgrammer NewbieSSProgrammer - 1 year ago 82
CSS Question

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(

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

Answer Source

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) {

// 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download