How to import third-party library files in the worker

all
code_library

#1

Excuse me.How to import third-party library files in the worker


#2

Hi @smartmango! To import third-party libraries, you’ll need to use a tool like Browserify or Webpack, then upload the entire bundled script as your worker. This will increase the size of your script substantially, but scripts can be up to 1MB in size, which should be enough to accomplish quite a bit.

To get you started, I can recommend a blog post that Simon Thompson put together a little while ago: he shows how to modify HTML content in a worker using Cheerio (a server-side jQuery implementation) which is imported using Browserify. You’ll probably find it helpful:

https://simon-thompson.me/simple-dom-manipulation-via-jquery-in-cloudflare-workers/

Harris


#3

OK. Thank you very much!