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.
Send messages from pages - JavaScript Tutorial
From the course: JavaScript: Service Workers
Send messages from pages
- [Instructor] When we have activated serviceworker we know it's not alone. We know we have clients such as browser's tabs, or Windows, PWAs or other items such as iFriends. So fortunately we do have a communication API that will let us send messages from pages to the serviceworker and vice versa. So let's start sending messages to the servicworker from Windows. And there we have an app.js file that's a (mumbles) file that is currently registering the serviceworker and that file is pointing from every HTML. Remember that if we are registering again a serviceworker that is already installed nothing will happen. So from there we can have for example, a function that will send a message to the serviceworker. We can receive a message and this is pretty simple. In fact it's based on the web worker messaging API. So we say navigator.serviceWorker .controller so that's the actual serviceworker .postMessage. So it's the same post message that probably you have seen before. And we can send the…
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.