29

When I am theming a Magento 2 store, what is the suggested way to clean the caches?

I edit the .less files and then I currently do

rm -rf pub/static/frontend/* var/view_preprocessed/ var/*cache/*

But this seems to be the brute-force method.

php bin/magento cache:flush --all

seems to not do the job.

Is there a better one?

2
  • since your question still as unresolved, please take a look at my answer here: magento.stackexchange.com/a/101139/27685, I think could help. Commented Feb 17, 2016 at 7:31
  • I'm also having a lot of problems with CSS/Less being cached, manually deleting the changed module in pub/static sometimes helps but not always. M2 is proving difficult to work with
    – Ben Crook
    Commented Apr 15, 2016 at 10:02

7 Answers 7

18

I think right way to refresh .less files now it's

php bin/magento setup:static-content:deploy

Because it "Collects, processes and publishes source LESS files"

Another point it's use dev mode during development then according to documentation "Static view files are not cached; they are written to the Magento pub/static directory every time they’re called"

To set Magento 2 to Developer mode you need to do following steps

  1. Delete the contents of the var/generation and var/di directories:

    rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/*

  2. Set the mode:

    php bin/magento setup:mode:set developer

6
  • 1
    there is no such deploy:mode:set command anymore (beta2). But I set MAGE_MODE via SetEnv. For dev:css:deploy I have to enter a file name. Which should I use?
    – Alex
    Commented Sep 14, 2015 at 20:31
  • sorry, this was my bad. setup:static-content:deploy is correct command for do that. also deploy:mode:set seems like still works for me, you are not have it in command list of bin/magento as well?
    – FireBear
    Commented Sep 14, 2015 at 23:05
  • got it, deploy:mode:set was changed also to setup:mode:set according to goo.gl/Pive1U
    – FireBear
    Commented Sep 14, 2015 at 23:13
  • I am still trying this stuff...
    – Alex
    Commented Sep 19, 2015 at 10:43
  • "Static view files are not cached; they are written to the Magento pub/static directory every time they’re called" I think the doc is wrong. There is a RewriteCond !-f in the .htaccess in pub/static which makes Apache to use the cached version if it exists.
    – Alex
    Commented Sep 19, 2015 at 16:02
2

There are three ways to clear the css cache, if the changes are not reflecting.

1. Use Grunt instead so you don't need to clean cache after every change of css (recommended way), you can see more documentation about grunt from check this link

2. Go to system > Cache Management > Additional Cache Management > Flush JavaScript/CSS Cache.

enter image description here

3. Run the deploy command (this takes a long and not a good recommendation, also change the mode to developer if it,s not there.)

php bin/magento setup:static-content:deploy
1

I think that pub/static contents (in dev mode) are generated with the same logic that is used for var/generation files, i mean, if the required content does not exists then is created but if already exist is reused.

So I think that you should clean pub/static[area] too or run setup:static-content:deploy to override all but this process is very slow to run every time you make a change.

0

In developer mode, instead of manually clear the pub/static and var/view_preprocessed.

Go to System > Tools > Cache Management and click Flush Static Files Cache.

0

You can run

grunt clean

or with more accuracy

grunt clean:<theme_name>

https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/css-topics/css_debug.html#grunt_commands

0

To flush magento cache in command like you can run:

bin/magento cache:flush

To flush storage cache you can run:

bin/magento cache:clean

To check status of the cache run (status should be on 1 for active and 0 for disabled):

bin/magento cache:status

To disable magento cache all together run:

bin/magento cache:disable

To enable cache run:

bin/magento cache:enable

But I think your issue resides in Magento mode being set on production mode. You can check your mode by using: bin/magento deploy:mode:show You can read more about magento production and developer mode here

As a alternative for developer mode on bin/magento setup:static-content:deploy you can use bin/magento setup:upgrade it clears compiled code and the cache. Or simply manually delete anything form the pub/static folder of your project that you need updated. If something is missing from that folder will be re-generated with latest changes.

0

With regards to CSS/LESS files modifications in custom themes, it looks like this one works pretty well to get the fresh version:

php bin/magento setup:upgrade

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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