Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script is:inline clarifications #1568

Merged
merged 4 commits into from
Sep 19, 2022
Merged

Script is:inline clarifications #1568

merged 4 commits into from
Sep 19, 2022

Conversation

Jutanium
Copy link
Contributor

What kind of changes does this PR include?

  • New or updated content

Description

@netlify
Copy link

netlify bot commented Sep 14, 2022

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 60eedb3
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/63288f365d975e000883614a
😎 Deploy Preview https://deploy-preview-1568--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice job 🙌

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@Jutanium
Copy link
Contributor Author

Note to self: clarify that type=module protects the scope of a script, so you need to use is:inline to add something to the global scope

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Dan — just left a suggestion.

Note to self: clarify that type=module protects the scope of a script, so you need to use is:inline to add something to the global scope

On this, it is possible to add to the global scope explicity from a type=module script, but it’s generally considered bad practice because of the async nature of modules (if you can’t control when each script runs, depending on globals across scripts is recipe for trouble).

<!-- Astro bundles this into a type="module" script -->
<script>
window.foo = 'some global value';
</script>

<!-- equivalent inline version -->
<script is:inline>
var foo = 'some global value';
</script>

Basically both of these should be avoided 😅

src/pages/en/reference/directives-reference.md Outdated Show resolved Hide resolved
Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Nicely done explaining this clearly without going deep into the weeds 👍

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@Jutanium
Copy link
Contributor Author

Everyone reviewed and approved this one, so I'm going to merge and bring any additional changes (regarding the module limitations) to a future PR!

@delucis I'm okay with the wordiness of the bundling explanation for now as it's in an advanced aside, but I may revisit it in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants