Skip to content

How do you use ky as a CDN without the UMD build? Is it possible? #318

Answered by sholladay
jc-camosun asked this question in Q&A
Discussion options

You must be logged in to vote

You can still load Ky from a CDN in the browser. You just need to use ES modules to do so.

There are two ways of doing this:

  1. Put your app in a <script type="module"> tag and then import Ky from the CDN and use it directly. The great thing about this is that it avoids using any global variables.

    // my-app.js
    import ky from 'https://unpkg.com/ky';
  2. Alternatively, in the HTML before your app, add a separate <script type="module"> tag that imports Ky and adds it to the global scope so that you don't have to modify your existing app.

    // ky-global.js
    import ky from 'https://unpkg.com/ky';
    globalThis.ky = ky;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants