From the course: JavaScript: Service Workers
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Load external files - JavaScript Tutorial
From the course: JavaScript: Service Workers
Load external files
- [Instructor] Let's load 02_06, Begin, and open serviceworker. In this case, we have all the code that so far is pretty small and only one file. But on a real project, we know that sometimes we don't want to write all the code in only one file. Or we might want to use additional third-party libraries that are targeting service workers. Fortunately for us, the service worker global scope has an importScript function. It a synchronous function receiving one or more URLs of additional JavaScripts that we want to load. So, for example, we can do events.js. I can create a new file here, I will call that file events.js, and inside that file, I'm going to move my two event handlers, pasting that part. So now my service worker has an additional file that is going to be downloaded and parsed at line 3. This is a synchronous API, which means if I have something on line 4, like console.log, that will be after loading the events.js script. Remember this is a synchronous API. If we want to load…
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.
Contents
-
-
-
-
Register a service worker4m 22s
-
(Locked)
Change the default scope3m 53s
-
(Locked)
Handle service worker events2m 50s
-
(Locked)
Debug with Developer Tools in Chrome5m 51s
-
(Locked)
Debug with other browsers3m 18s
-
(Locked)
Load external files3m 6s
-
(Locked)
Work with the registration5m 52s
-
(Locked)
Update the service worker5m 36s
-
(Locked)
Manage updates in your code4m 24s
-
(Locked)
Unregister the service worker3m 22s
-
-
-
-
-
-