Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@dschz/solid-create-script

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dschz/solid-create-script

Solid utility hook to dynamically load an external script.

latest
Source
npmnpm
Version
1.2.8
Version published
Maintainers
1
Created
Source

solid-create-script

@dschz/solid-create-script

License npm Bundle Size JSR CI

SolidJS hook to load external scripts -- built on top of @dschz/load-script.

✅ Features

  • 📑 Fully typed with TypeScript
  • ✏️ Built on top of @dschz/load-script inheriting all the same features.
  • 📆 Declarative async tracking via Solid's createResource

📦 Installation

npm install solid-js @dschz/load-script @dschz/solid-create-script
pnpm install solid-js @dschz/load-script @dschz/solid-create-script
yarn install solid-js @dschz/load-script @dschz/solid-create-script
bun install solid-js @dschz/load-script @dschz/solid-create-script

These are peer dependencies, so you must install:

  • solid-js
  • @dschz/load-script

🧠 API

createScript(src, options?, container?)

Loads an external script dynamically and returns a Resource<HTMLScriptElement>.

Parameters:

NameTypeDescription
srcstringScript URL (required)
optionsLoadScriptOptionsloadScript options (e.g. async, type)
containerHTMLElementHTML element to append <script /> to (default: document.head)

🧪 Example

import { Switch, Match } from "solid-js";
import { createScript } from "@dschz/solid-create-script";

const CustomComponent = () => {
  const script = createScript("https://example.com/widget.js", { async: true });

  return (
    <Switch>
      <Match when={script.loading}>Loading Script...</Match>
      <Match when={script.error}>Failed to load</Match>
      <Match when={script()}>Script is ready!</Match>
    </Switch>
  );
};

📝 Notes

  • Scripts are cached by src unless innerHTML or textContent is used
  • Scripts are not automatically removed on cleanup/unmount
  • Designed to be simple and safe to use inside SolidJS components (in SSR and non-SSR environments)

💬 Feedback & Contributions

Feel free to open issues or submit pull requests. PRs are welcome!

Keywords

solid

FAQs

Package last updated on 05 Jun 2025

Did you know?

Socket

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.

Install

Related posts