Skip to content

Commit

Permalink
fix: improve first load time (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigby90 authored Jan 28, 2022
1 parent 8d4029b commit d1c69ed
Showing 1 changed file with 14 additions and 9 deletions.
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

0 comments on commit d1c69ed

Please # to comment.