From the course: JavaScript: Service Workers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Synthesize a response - JavaScript Tutorial
From the course: JavaScript: Service Workers
Synthesize a response
- [Instructor] I'm back in the code. I'm in the Begin folder, in 03_02, and so far, we have been listening for the fetch event. So we are actually seeing all the network requests that are going through our service worker, but we are not actually doing anything with that. So besides doing a console load, we can take the event argument and execute a function known as respondwith. And that's the function that has all the power inside service workers. Because we can respond with an HTTP response, or a promise of that object. In our case, we are going to start creating a response that we will create on the fly. So in a static response that I'm going to create right here. And for that, I'm going to use a response constructor available in Java Script within the service worker. This is an actual http response that we are synthesizing from our service worker. That receives at least one argument that's mandatory to the body. So, basically, what we want to show in the browser. So for now, I can…
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.