Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: improve first load time #179

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/Vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\HtmlString;
Expand Down Expand Up @@ -225,19 +226,23 @@ protected function shouldUseManifest(): bool
*/
public function isDevelopmentServerRunning(): bool
{
try {
['host' => $hostname, 'port' => $port] = parse_url(config('vite.ping_url') ?? config('vite.dev_url'));
$connection = @fsockopen($hostname, $port, $errno, $errstr, config('vite.ping_timeout'));
if (isset($this->isDevelopmentServerRunning)) {
return $this->isDevelopmentServerRunning;
}

if (\is_resource($connection)) {
fclose($connection);
$url = config('vite.ping_url') ?? config('vite.dev_url');

return true;
}
} catch (\Throwable $th) {
try {
/**
* The below will throw an exception if no dev server is running.
*/
Http::get($url);

return $this->isDevelopmentServerRunning = true;
} catch (\Throwable $e) {
}

return false;
return $this->isDevelopmentServerRunning = false;
}

/**
Expand Down