What are loaders (view->makeLoader()) and why are they needed?

Hi,

I have an application (Wordpress-based) running on WPEngine, a host with notoriously strict security policies that, amongst other things, prevent the web server from writing files. The known workaround for this with Sage is to pre-compile all Blade templates after each deployment. This has worked for me in the past, however in this case I am using Woocommerce via generoi/sage-woocommerce, which makes uses of “loaders”. Would somebody be able to explain why it is necessary to include a “loader”, rather than including the compiled view directly itself?

I have written a helper command to “pre-compile” these loaders too, but it doesn’t work because the id/hash in the filename seems to be different on the server so it ends up trying to rebuild them on the fly anyway.

TIA.

1 Like

We have exact the same problem, also thought of the approach to build a script to pre-compile them too. But did you manage to fix it/fit the script?

Sadly not. Each time I solved one problem, another arose. For various reasons, this issue being one of them, we migrated this project to another host without these limitations. Please do update me if you manage it though!

Well, we now kinda solved it by not using the wc_get_template function but @include functions for the templates we include in our regular views. It seems to an ok-ish solution.
Though bypassing this function feels like we might hit some bumps further down the road.

I now created the issue on github for generoi/sage-woocommerce as well:

Ah yes, that wouldn’t work for us in our situation. Thanks for submitting the issue on Github, will keep my eye out for updates!

I published GitHub - generoi/sage-cacheable-viewloaders which should make the view loaders cacheable, haven’t really tried it much so open up an issue if it doesn’t work.