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?
-
since your question still as unresolved, please take a look at my answer here: magento.stackexchange.com/a/101139/27685, I think could help.MauroNigrele– MauroNigrele2016年02月17日 07:31:51 +00:00Commented 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 withBen Crook– Ben Crook2016年04月15日 10:02:48 +00:00Commented Apr 15, 2016 at 10:02
7 Answers 7
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
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/*Set the mode:
php bin/magento setup:mode:set developer
-
1there is no such
deploy:mode:setcommand anymore (beta2). But I setMAGE_MODEviaSetEnv. Fordev:css:deployI have to enter a file name. Which should I use?Alex– Alex2015年09月14日 20:31:53 +00:00Commented 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– FireBear2015年09月14日 23:05:04 +00:00Commented Sep 14, 2015 at 23:05
-
got it, deploy:mode:set was changed also to setup:mode:set according to github.com/magento/magento2/blob/…FireBear– FireBear2015年09月14日 23:13:47 +00:00Commented Sep 14, 2015 at 23:13
-
I am still trying this stuff...Alex– Alex2015年09月19日 10:43:43 +00:00Commented 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 !-fin the.htaccessinpub/staticwhich makes Apache to use the cached version if it exists.Alex– Alex2015年09月19日 16:02:24 +00:00Commented Sep 19, 2015 at 16:02
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.
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
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.
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.
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
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.
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
Explore related questions
See similar questions with these tags.