Preloading a Web Worker used to be fairly difficult. Each of the pages below demonstrate a potential technique for doing so, with varying degrees of success.
Using <link rel="preload" as="worker">
, which is not implemented by any browsers.
Using <link rel="prefetch">
works, but prefetch only populates the HTTP cache - it won't pre-parse or store cached bytecode.
Using <link rel="preload" as="script">
to preload a script, and a small "shim" Worker that loads the script using importScripts()
.
Using <link rel="preload" as="script">
to preload a script, and an inline "shim" Worker that loads the script using importScripts()
.