Portfolio site, Part 2: Surprise, it's a service worker

In this blog post, Morgan reports live from the cutting edge ofweb development and technology.

So, I’m digging into the Topeka App, ripping out its organs, sewing my name on them, and putting them back. It’s not long before I’m hitting refresh in my browser and wondering why I don’t notice any changes rendering.

I’m looking at the index.html file in my source andsee my changes there! What the hell is going on. Here’s a snapshot of what I’m looking at:


I see “my” new polymer elements in this file, but I’m looking at the same old Topeka App. I see my css changes in the theme.css file too. I don’t even know what to google: “browser not doing what i tell it to do”, or “screw you chrome, respect my authority!”.

Time to sniff around. What don’t I recognize? I don’t recognize the script tag at the top:

if (!('import' in document.createElement('link'))) { var Platform = {flags: {shadow: true}}; }

Actually, I still don’t know what that’s about. But there’s a comment above it saying it’s to diagnose an old version of Chrome in order to know when to use a polyfill for Polymer and the shadow DOM.

This is unfamiliar though:

if (navigator.serviceWorker) { // Register our ServiceWorker navigator.serviceWorker.register("sw.js"); }

What the hell is sw.js and why isn’t it in my developer toolbox, under sources?

So, let’s go visit githuband find out what’s in the mystery file. It looks like javascript but altogether still alien, to me at least. Except I see the word “cache” throughout, and now I know something is up. Let’s just commentthat part of index.html out and do some hard refreshes (dumping the cache), and see if that does it.

It does.

Now what the hell is the navigator.serviceWorker?

Google that and the best you can find (today) is this article on html5 rocks and this video from Google I/O last year. Or there’s this presentation, also made at Google I/O.

Oh, so Google’s just trying to make it so that when you try to visit your favorite web application, from an airplane or a cave, you get the same great experience you would with internet. Interesting.

If you’re like me, you can feel a little smugger (apparently that is a word) about just knowing what aserviceWorker even is and the fact that it tried to jam you up but didn’t know who it was fuc$ing with ( – riddick inpitch black; it doesn’t sound as good when you say “whom”).