diff --git a/src/Facades/Endpoint/URL.php b/src/Facades/Endpoint/URL.php index cd4e1261b6..037a1bc7cf 100644 --- a/src/Facades/Endpoint/URL.php +++ b/src/Facades/Endpoint/URL.php @@ -14,6 +14,8 @@ */ class URL { + private static $externalUriCache = []; + /** * Removes occurrences of "//" in a $path (except when part of a protocol) * Alias of Path::tidy(). @@ -221,14 +223,31 @@ public function format($url) */ public function isExternal($url) { - if (! $url || Str::startsWith($url, ['/', '#'])) { + if (isset(self::$externalUriCache[$url])) { + return self::$externalUriCache[$url]; + } + + if (! $url) { return false; } - return ! Pattern::startsWith( + if (Str::startsWith($url, ['/', '#'])) { + return self::$externalUriCache[$url] = false; + } + + $isExternal = ! Pattern::startsWith( Str::ensureRight($url, '/'), Site::current()->absoluteUrl() ); + + self::$externalUriCache[$url] = $isExternal; + + return $isExternal; + } + + public function clearExternalUrlCache() + { + self::$externalUriCache = []; } /** diff --git a/src/Listeners/ClearState.php b/src/Listeners/ClearState.php index 8d01a67c49..ced2b006fa 100644 --- a/src/Listeners/ClearState.php +++ b/src/Listeners/ClearState.php @@ -2,6 +2,7 @@ namespace Statamic\Listeners; +use Statamic\Facades\URL; use Statamic\Statamic; use Statamic\View\State\StateManager; @@ -11,5 +12,6 @@ public function handle() { Statamic::clearApiRouteCache(); StateManager::resetState(); + URL::clearExternalUrlCache(); } }