
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
gatsby-script
Advanced tools
An enhanced script component for Gatsby sites with support for various loading strategies
An enhanced script component for Gatsby sites with support for various loading strategies.
You do not need to install this package directly, it is available in the main Gatsby package since gatsby@4.15.0
.
See the documentation for full details.
import * as React from "react"
import { Script, ScriptStrategy } from "gatsby" // Re-exported from core
const GTM = `G-XXXXXXXXXX` // Example Google Analytics 4 identifier
// Example script sources for illustration
const scripts = {
three: "https://unpkg.com/three@0.139.1/build/three.js",
marked: "https://cdn.jsdelivr.net/npm/marked/marked.min.js",
gtag: `https://www.googletagmanager.com/gtag/js?id=${GTM}`,
}
// Strategy prop is optional, defaults to post-hydrate
function IndexPage() {
return (
<main>
<h1>Script component example</h1>
<Script src={scripts.three} strategy={ScriptStrategy.postHydrate} />
<Script src={scripts.marked} strategy={ScriptStrategy.idle} />
<Script
src={scripts.gtag}
strategy={ScriptStrategy.offMainThread}
forward={[`gtag`]}
/>
<Script id="gtag-config" strategy={ScriptStrategy.offMainThread}>
{`
// Example configuration of Google Analytics for use in Partytown
window.dataLayer = window.dataLayer || [];
window.gtag = function gtag() { window.dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', ${GTM}, { send_page_view: false })
`}
</Script>
<Script
id="my-unique-id"
dangerouslySetInnerHTML={{ __html: `alert('Hello world')` }}
/>
<Script id="my-unique-id-2">{`alert('Hello world')`}</Script>
</main>
)
}
export default IndexPage
FAQs
An enhanced script component for Gatsby sites with support for various loading strategies
The npm package gatsby-script receives a total of 182,179 weekly downloads. As such, gatsby-script popularity was classified as popular.
We found that gatsby-script demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.