Cloudflare Worker - lazy loading

Hi all,

I am wondering if it’s possible to lazy load code/JSON in order to improve the Worker’s performance?
Something like this:

addEventListener('fetch', async (event) => {
  if (condition) {
    const handleBot = await import(./handleBot.js) // only loaded at call time

    event.respondWith(handleBot(event))
  } else {
    event.respondWith(responseWithAsset(event))
  }
}

You can do dynamic imports with workers.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.