I have updated the CSS for our site.

After updating, I ran the below commands:

php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

But the changes are not applied when I check the front-end of our site. So, I ran the below command:

php bin/magento setup:di:compile

I also ran the above said 2 commands after this. Now, I can see the changes in the front-end.

So, In this case, do I need to run compile command whenever I make any changes in CSS.

Your help will be greatly appreciated.


When you are making any changes related to Html, CSS, or js file & you are into the developer mode then you need to run the only below two commands:

php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

These commands will generate your changes if it is not generating the changes it means there is some problem with the server in the file generation this is the old problem magento facing many times it is some times because of the cache also.

The alternative for this & when you are in the production mode is you can delete the var/view_preprocessed/, var/composer_home/cache/, var/cache/, var/page_cache/, pub/static/frontend folders & then deploy the static content for that run the below command

rm -rf var/view_preprocessed/ var/composer_home/cache/ var/cache/ var/page_cache/ pub/static/frontend
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

If you are making the CSS changes & for that if you are writting the less files then you can run the grunt command for the compilation of the less to css & using it you don't need to run the above commands. You can refer this devdocs for it.

To know when to run which commands you can refer this answer Magento 2: When should I run which commands?

| improve this answer | |
  • Perfectly working. Thanks! – Siva Apr 2 '19 at 9:32
  • You are always welcome happy coding! ;) – Abhishek Tripathi Apr 2 '19 at 9:33


setup:di:compile creates the generated PHP-classes used by Magento2 (Interceptors, Factories, ...)

This command also clears some generated files.

setup:static-content:deploy will regenerate all CSS. But you normally do not need this when developing. Make sure you are in the developer mode.

| improve this answer | |
  • Yes, I'm in the developer mode. – Siva Apr 2 '19 at 7:35

Yes you will need to run bin/magento setup:di:compile when you added new classes with dependencies (constructor parameters) or changed dependencies of existing classes.(di.xml)

Another main thing here is Code compilation. setup:di:compile command compiles your code everytime. its compile the code and check is there any error in that code or not , if error is there it will show directly on the command prompt in red color.

While developing your extension in magento 2 and upper versions whenever you change any custom logic or some front end side operations there is no need to run this command . But if you change something in either di.xml or class ,factory method etc etc ... then you must need to run this command.

Refer this link for more details - http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-compiler.html

| improve this answer | |
  • that's just wrong... you do NOT need to run it everytime – Philipp Sander Apr 2 '19 at 7:37

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.