Magento 2 – Clearing the blasted caches and static files

I have never used a programming framework seemingly designed to frustrate the development process as much as Magento 2.  You have to constantly clear caches and static files to see your modifications, even when in developer mode.

Oddly, you can’t even clear everything you need to from the Magento admin – you need to use the CLI.

Anyhow here is my short cut list for clearing out the junk…seemingly every 2 minutes.

All of this is run from the Magento project root.

Clear the cache folder:

rm -rf var/cache/*

Clear the preprocessed files:

rm -rf var/view_preprocessed/*

Clear the static frontend files:

rm -rf pub/static/frontend/*

Clear the page_cache:

rm -rf var/page_cache/*

If you like you can run all of these at once:

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

Now a common problem when clearing the static files, especially in developer mode, is that none of them show up on the front end.  The main culprit for this is that, in developer mode, symlinks are created to the static files.  People often clear out the whole pub/static folder…which includes the important .htaccess which allows all the symlink cleverness to take place.

My tips for this:

  1. make a copy of pub/static/.htaccess  (maybe to pub/status-htaccess-backup)  in case you do delete it.
  2. Change the permissions on the .htaccess file to r-r-r.
  3. Just be careful deleting static files and don’t do rm -rf pub/static/*

Another problem I have encountered is that, even after clearing all the caches and what-have-you, I end up viewing the same page as before in my browser or, for a while, a white screen.   I found that by adding a url parameter  such as ?x=1 (then x=2, x=3, and so on) will force the browser and Magento brain to generate stuff as if it was a new URL.


Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *