#Static page, but JS is still shipped

3 messages · Page 1 of 1 (latest)

rare osprey
#

i have a completely static page with imports only from .astro and .html files, which all dont conatin any js, except for one script tag inside of a .html file. It all works even if i block the request to the one js file, as it seems to be some kind of runtime? I would like toremove it from the build as it isn't needed at all

prisma barnBOT
#

Hi @rare osprey. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro by default processes and bundles all <script> tags in your components, even if they are not used in the final output. This is part of Astro's build process which works on the module graph. Once a component is included in the template, its <script> tags are processed, optimized, and bundled, whether it appears in the final output or not source (https://docs.astro.build/en/guides/troubleshooting/#an-unexpected-script-or-style-is-included).

However, you can prevent Astro from processing a script by adding the is:inline directive to your script tag. This will render the script into the HTML exactly as written. Local imports are not resolved and will not work. If the script is in a component, it repeats each time the component is used source (https://docs.astro.build/en/guides/client-side-scripts/#opting-out-of-processing).

For HTML components, any <script> tags are left unbundled, treated as if they had is:inline source (https://docs.astro.build/en/basics/astro-components/#html-components).

Here's an example of how to use the is:inline directive:

<script is:inline>
  // Your script here
</script>

Please note that this approach skips the JavaScript processing, bundling, and optimizations that are provided by Astro. However, this may be preferred for any scripts that have already been published and minified separately from Astro source (https://docs.astro.build/en/guides/upgrade-to/v1/#how-to-resolve-javascript-files).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: