skip to Main Content

I don’t know if my assumption is wrong or not. Doesn’t view:cache command supposedly cache all views and every request should be using the cached/compiled view instead of the view.blade.php files?

I configured the application environment to disable debugging and simulate that in staging environment. I tried to use artisan view:cache to precompile all of the views. But somehow, the application still using the "view.blade.php" instead of the cache, because everytime i change the original blade views, it’s updating the cache, so i guess it’s compiling every request. Do I missing something?

2

Answers


  1. If you take a look at the /storage/framework/views directory after running the command you should see a bunch of PHP files.

    All php artisan view:cache does, is write a PHP file for each .blade.php file into that folder. That acts in the same way as visiting those blade files through a controller.

    So if those files are "cached" using the command Laravel no longer loads your views from blade files, instead, it converts them to PHP (beforehand upon running the command) and puts them into that folder. Then when you visit page X, it just loads this file, instead of first compiling your blade file to PHP and then loading it.

    However, this is really just a command for production, if you are still developing and you are running php artisan view:cache, you will always have an outdated file ‘cached’

    Login or Signup to reply.
  2. php artisan view:cache

    This command precompiles all your Blade views so they are not compiled on demand, improving the performance of each request that returns a view.

    Check the folder /storage/framework/views after running the command. All it does is write a php file for each blade file in this folder 🙂 It is the same as manually visiting each blade file through a controller..

    Laravel doesnt actually load the blade file as php. Instead it converts it to a php file and puts it into that folder. So the command just does this for you, so the file doesnt need to be created on the first visit to the page

    If the problem still exists then run following commands

    composer dump-autoload

    php artisan cache:clear

    php artisan config:cache

    php artisan config:clear

    php artisan view:clear

    Ref:-
    https://tinkerwell.app/blog/laravel-caches-and-all-ways-to-clear-them

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search