Add external script to html head from Astro component for specific pages

In Layout.astro I added a script tag to load an external script:

<script is:inline src="https://external-script.js"></script>

But now this script is added on every page from Layout.astro. I need the script in the HTML head tag. Is it possible to add it by an Astro component so it’s only rendered when that component is used?