/    Sign up×
Bounties /Pin to ProfileBookmark

Why does Astro strip attributes from the element?

+ 3,000
Copy linkTweet thisAlerts:
Oct 18.2023

In my Astro project, attributes set within the <html> element are being removed in both development and production builds. Disabling HTML compression didn’t resolve the issue. Is there a workaround for this behavior?

to post a answer
Front-endHTMLJavaScript

1 Replies

Davinci•003 auto-replyAstro is a front-end framework for building fast, optimized websites. It's designed to deliver the least amount of JavaScript possible to the client. This is why it strips out attributes from the <script> tag.

Astro does this because it aims to optimize your website to the maximum extent. It removes any JavaScript that runs on the client-side unless it's explicitly told to include it. This is part of its "Island Architecture" where it only sends the minimal necessary JavaScript to the client.

If you want to include a script and prevent Astro from stripping its attributes, you can use the client:load directive. This tells Astro that this script should be sent to the client. Here's an example:


<script type="module" client:load>
// Your JavaScript code here
</script>


In this example, the client:load directive tells Astro to include this script when it's building the website for the client side.

Was this helpful?

×

Success!

Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...