I’m not sure if this is the right place to ask this, so let me know if this is improper and I’ll make a new topic.
I recently found out that, in Sage 9, Blade is setup to compile templates to PHP files and write them to the media uploads folder. If the file changes, Blade will recompile the file and write the update to the cache. If the file has not changed, and it already exists, it will be loaded from the cache.
I think that’s great that it has a cache. It saves CPU and makes sense.
However, I’m wondering if there’s a way to precompile the cache when I deploy to the server, rather than the default behaviour of checking upon page request.
I found this out because I’m using a plugin to offload the media uploads to s3, and it caused pages to stop loading (white screen of death). The blade cache was being offloaded to s3, and then could not be loaded because allow_url_include
is (and definitely should be!) disabled, so PHP from remote servers cannot be executed. So I had to change the directory where Blade stores its compiled templates to ensure it’s stored and loaded locally. (For me, the config to change it was at /src/setup.php:127, changing view.compiled
to WP_CONTENT_DIR . "/uploads/cache/compiled"
instead of "{$paths['dir.upload']}/cache/compiled"
).
It would make a lot more sense to be able to precompile the templates. They aren’t going to change between deploys, and then I can set my file system to truly be read-only and harden it up.
Is there a way to force Blade to precompile the files upon deploy and stop the compile-on-request behaviour? I tried looking at Laravel’s docs and searching the web and couldn’t find anything about this.