5

When aggregating CSS/JavaScript files using performance page in Drupal 8, drush cc css-js doesn't work, and I've to clear/rebuild all cache.

Is this a bug or the normal behavior?

How do I properly clear/rebuild only the JavaScript/CSS cache?

I want that the filenames change too, so that the browser resets its cache too.

  • 1
    You can disable aggregation in the settings.local.php file. – Eyal Jul 1 '16 at 8:47
  • but i want to keep aggregation enable :) – Cawet Jul 2 '16 at 9:52
1

NOTE: I am using the s3fs plugin in order to store assets in an AWS S3 bucket, so if you are not using that your results could differ

This is probably not a suggested method of forcing the system to clear the asset cache, but I was in the same boat and for some reason my file systems got mixed up during multiple edits between local, development, and the live site. For the live site I was only able to get the styles working if the files were not aggregated using the Performance page.

As far as I know, the system will not update the CSS or JS files unless a change has been detected. Aside from going in and making a change to every file I started digging into the database. I found that the file location for the CSS and JS assets were located in the "cache_default" table with a value of something like below:

s3fs:uri:public://css/css_0WFR6_Et4WEJOkLOOpdg4f7EmvMRhsPkSk7KcrPyct4.css

and

s3fs:uri:public://js/js_-YxTfPGZervj7hTx1tF6zyt9ua2DxHPROTbub3I_WRg.js

BACKUP YOUR DATABASE BEFORE GOING FURTHER! In case you mess anything up, CYA!

  1. I went through and deleted all entries that were a CSS or JS file. Be careful not to delete the directory reference entries that just have the JS and CSS folders.
  2. THEN, since I was using s3fs I went into the "s3fs_file" table and did the same thing.
  3. I went back into the Performance page, enabled the CSS and JS aggregation, and saved.
  4. Then cleared the site cache after that. This seemed to re-generate the CSS and JS assets, re-built the asset table data, and the site was back to normal!

I did have to dump the DB tables and import into my dev and local environments in order to mimic the new asset names, but this seemed to work like a charm.

SIDE NOTE: I am wondering if there would be some way for Drupal to add a style versioning system? Maybe that we could change the sites CSS versioning after major changes in order to have this done automatically? or maybe this is just something I will need to build my next module for!!

| improve this answer | |
-1

You can run drush ev command to clear css-js cache, check example below:

drush ev '\Drupal::service("asset.css.collection_optimizer")->deleteAll(); \Drupal::service("asset.js.collection_optimizer")->deleteAll(); _drupal_flush_css_js();'

Above sample is taken from here.

| improve this answer | |
  • This seem good, but i can't test it until monday, i'll accept your answer at this time :) – Cawet Jul 2 '16 at 9:55
  • ok i tested right know. I forgot to say it but i want that the file name change too , otherwith the brother don't reset his cache either. This command reset cache, but keep the same file name :/ – Cawet Jul 4 '16 at 13:56
  • sorry i fact it's not reset aggregate file neither . it seam to do the same as drush cc css-js – Cawet Jul 7 '16 at 10:12
  • This no longer seems valid. I used only de css part: drush ev '\Drupal::service("asset.css.collection_optimizer")->deleteAll(); _drupal_flush_css_js();' It did not clear the css cache and I needed to use drush cr again. – ñull Aug 16 '19 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.