In my previous post on Load Dynamically Livewire Components from Different Namespace, I've hit an issue which causing my boot time to load the Laravel application is very slow.
On my machine, it run about 500-800ms, but for my team, sometimes they hit around 5-6 minutes to load for just a page.
So the journey begin to find out what's the issue, why it's taking so long to boot up. At first, I'm looking at my route files, which I have a lot of route files been loaded dynamically like the following:
collect(glob(base_path('/routes/web/*.php')))
->each(function ($path) {
require $path;
});
Then I change the route to:
require 'web/_.php';
require 'web/user.php';
Well, not much different, just about -10ms better.
So digging up my codes, see, what other things may caused until I remembered that I have a service provider, which load dynamic Livewire components in different domains in app/
directory.
One thing I noticed, I misconfigured to load the Livewire classes from /app
instead of /app/Domains
.
You can imagined how many files under app/
directory need to be load on initial load. 😬
With that in mind, I've tried to change from following:
public function register()
{
if (class_exists(Livewire::class)) {
$this->load(base_path(config('livewire-domain.path')));
}
}
To the following:
public function register()
{
if (class_exists(Livewire::class)) {
$this->load(config('livewire-domain.paths'));
}
}
And my config file as following:
'paths' => [
app_path('Domain/Profile'),
app_path('Domain/User'),
],
Well the result?
Top comments (0)