After researching service workers a bit, none of the tutorials seem to explicitly state what self actuall is. It's a ServiceWorkerGlobalScope implementation. The events passed to the install and activate listeners are ExtenableEvent implementations. This is where the waitUntil method comes from to force an event listener to wait until a promise resolves. The install… Continue reading What is Self in a Service Worker?
Category: JavaScript
Handling Authentication Tokens in Single Page Apps
There are broad scenarios in which a single page app (SPA) needs to handle authentication: The SPA is using an API custom built for the app itself -- the API being used is not public in any other way The SPA is using an API built for public consumption -- one with a full fledged… Continue reading Handling Authentication Tokens in Single Page Apps
Assertion Error Diffs with Karma, Mocha, and Chai
Promises are Not for Control Flow
Common advice in languages with exceptions is that exceptions are not for control flow. A rejected promise is not any different than a thrown exception: in both cases something when exceptionally wrong and must be dealt with. This week I was fighting with promises while building a slack app because I was attempting to use… Continue reading Promises are Not for Control Flow
Beautiful Imports in NodeJS
One of the things I enjoy about ECMAScript modules is their ease on the eyes. They look good -- the same way Python's import statement can look nice. It's also nice to have to explicitly import the things necessary for a file/module to its work. Need the whole module? That's a choice that has to… Continue reading Beautiful Imports in NodeJS
Building an Upload System Backed by S3 and Client-Side Uploads
One of the things I try to do when building applications is keep servers stateless. This makes those servers easy to throw away -- a piece of infrastructure failing (which it always will) is not a big deal with stateless servers. Just spin up a new one. When the requirement came down the pipeline to… Continue reading Building an Upload System Backed by S3 and Client-Side Uploads
How to Monitor Client-Side Upload Progress (with XMLHttpRequest)
Showing a user something like a progress bar during a file upload is handy and let's them know that stuff is working. Higher level abstractions like fetch don't really provide a look into how much of a request body has been sent, but good ol' XMLHttpRequest does. In order to monitor upload progress, attach an… Continue reading How to Monitor Client-Side Upload Progress (with XMLHttpRequest)