The past few weeks I have had the pleasure of interning at ActBlue as a tech intern. It's been a great experience and I've had the opportunity to work on a few cool projects. One of my favorite projects during this time, has been experimenting with service workers to prototype a potential new app feature. So go pour yourself a cup of coffee, relax back in your favorite chair, and get ready to learn about an awesome new web technology.
So what's the deal with service workers? (I promise this isn't a Seinfeld joke)
As of today, out of the four big browsers in use: Internet Explorer, Chrome, Safari and Firefox, only Chrome and Firefox provide support for service workers. So you're limited by potential users, but don't let that fool you. Service workers are very powerful. It allows you to do really cool stuff like send messages to your users without them having to actually be on your website. The browser, however, must be open. You can make your website run faster and even keep running when offline. No internet connection? No problem. Keep enjoying your website experience on ActBlue. In the future, there is even talk of websites having geofencing capabilities using service workers. Oh, what's geofencing? Imagine being on ActBlue's website while walking around New York City. Which, of course, for your safety, I urge you not to (considering how often people get hit by cars there). But, for the sake of this blog post, let's say you are walking around NYC on ActBlue’s website, you could potentially trigger different pieces of code to run based on your current location.
So what exactly is a Service Worker?
Since it runs on a different thread, you can't access the DOM in your service worker code and, for security purposes, you can only use service workers on pages that are served over HTTPs. Finally, the service worker is event-driven. It listens for some sort of event and then when it detects that event, some code is executed.
And, there you have it, that is a service worker. Welcome to the future of the web… potentially.
And if any ActBlue campaign admins out there have read this far, stay tuned for some sweet push contribution notifications.