From the course: JavaScript: Web Workers
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Import external scripts - JavaScript Tutorial
From the course: JavaScript: Web Workers
Import external scripts
- [Instructor] When we are creating workers, sometimes we just write the worker job in one file. But sometimes we want to use libraries. We want to share libraries between different workers, or we just want to split our code in different files. The Web Workers API supports a way to import external scripts, because we don't have html inside the worker so we can't just add on the script tag. In this case, we use the function known as import the scripts. It receives one or more URLs of the scripts that you want to load. You can import the scripts from third-party origins, at least by default. So you can import one script, or more than one at the same time. It's a synchronous API, which means the thread will help there, downloading the script file parse in the file and executing the file at exactly that point. You can code it once with several files. In that case it will load all the files, sometimes in parallel, and then they will execute the files in order. Or we can have more than one…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.