importScripts
hack
Preloads a Classic Worker using <link rel="preload" as="script">
,
then loads a tiny inline worker using a Data URL, which then imports the script via importScripts()
.
This works because, unlike Worker()
, importScripts()
loads scripts
using the script
resource type, just like <script>
.
One caveat with this approach is that, due to the use of a Data URL as the initial Worker source, the Worker is created with an Opaque Origin.