#Extract script tags from Astro components (CSP / inline scripts)

5 messages · Page 1 of 1 (latest)

rain agate
#

I have a hard time understanding the difference between

<script type="module">

and

<script is:inline type="module">

when in both scenarios the build output includes an inlined script 🤔 I'd like to know how can I write an ESM script that gets extracted to its own file by Astro, so my CSP wouldn't have to include unsafe-inline for the script-src directive (https://docs.astro.build/en/guides/troubleshooting/#refused-to-execute-inline-script 👎 )

Docs

Need help? Stuck on something? We've got you covered.

undone imp
#

both behave the same

#

is:inline is necessarily added to all scripts that have an attribute

#

how can I write an ESM script that gets extracted to its own file by Astro
by adding this config

export default defineConfig({
    ...
    vite: {
        build: {
            assetsInlineLimit: 0
        }
    }
    ...
})
#

it will make sure most scripts and styles processed by astro are linked instead of inlined