wishy

1.0.2 • Public • Published

Wishy

Wishy allows you to dynamically import scripts, adding them as <script> tags in the DOM. Its name comes from wishy-washy, meaning indecisive.

Why?

You could and should use dynamic import() to load ES6 modules, but unfortunately not all things are written that way. Wishy allow you to import simple scripts.

How to use it

Just call the wish function with a list of paths to the scripts you want to import. You can also put in an object and wishy will interpret key/vales as attributes. The <script> tags are added to a <div> with class "_wishywashy". For example:

wish([
  "path1",
  {
    "src": "path2"
    "key": "value"
  }
  ])

is rendered in the DOM as

<div class="_wishywashy">
  <script src="path1"></script>
  <script src="path2" key="value"></script>
</div>

You can remove all <script> tags from the DOM with the wash() function, but that won't remove them from memory.

How to install it

Just plain import the script. It'll create a function called "wish()" to which you pass your script paths and a "wash()" to remove them.

Caveats

Note that any script loaded by wishy is deferred and won't be executed synchronously. Wish is written in ES6. Calling wish() inside a module script won't work.

Readme

Keywords

Package Sidebar

Install

npm i wishy

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

3.27 kB

Total Files

7

Last publish

Collaborators

  • isacvale