protected function jsTagsAfter($asset, $rawHtml, $insidehead = false)
    {
        if ($insidehead) {
            $pos = strpos($rawHtml, '</head>');
            $context = substr($rawHtml, 0, $pos);
        } else {
            $context = $rawHtml;
        }

        // This match tag is a unique case
        if ($matches = $this->getMatches($context, '(.*)</script>', false, true)) {
            // Attempt to insert it after the last <script> tag within context, matching indentation.
            $last = count($matches[0]) - 1;
            $replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);

            return Str::replaceFirst($rawHtml, $matches[0][$last], $replacement);
        } elseif ($insidehead) {
            // Second attempt: entire document
            return $this->jsTagsAfter($asset, $rawHtml, false);
        }

        return $this->headTagEnd($asset, $rawHtml);
    }