Tags: internet

197

sparkline

Monday, October 8th, 2018

Sunday, September 23rd, 2018

Service workers in Samsung Internet browser

I was getting reports of some odd behaviour with the service worker on thesession.org, the Irish music website I run. Someone emailed me to say that they kept getting the offline page, even when their internet connection was perfectly fine and the site was up and running.

They didn’t mind answering my pestering follow-on questions to isolate the problem. They told me that they were using the Samsung Internet browser on Android. After a little searching, I found this message on a Github thread about using waitUntil. It’s from someone who works on the Samsung Internet team:

Sadly, the asynchronos waitUntil() is not implemented yet in our browser. Yes, we will implement it but our release cycle is so far. So, for a long time, we might not resolve the issue.

A-ha! That explains the problem. See, here’s the pattern I was using:

  1. When someone requests a file,
  2. fetch that file from the network,
  3. create a copy of the file and cache it,
  4. return the contents.

Step 1 is the event listener:

// 1. When someone requests a file
addEventListener('fetch', fetchEvent => {
  let request = fetchEvent.request;
  fetchEvent.respondWith(

Steps 2, 3, and 4 are inside that respondWith:

// 2. fetch that file from the network
fetch(request)
.then( responseFromFetch => {
  // 3. create a copy of the file and cache it
  let copy = responseFromFetch.clone();
  caches.open(cacheName)
  .then( cache => {
    cache.put(request, copy);
  })
  // 4. return the contents.
  return responseFromFetch;
})

Step 4 might well complete while step 3 is still running (remember, everything in a service worker script is asynchronous so even though I’ve written out the steps sequentially, you never know what order the steps will finish in). That’s why I’m wrapping that third step inside fetchEvent.waitUntil:

// 2. fetch that file from the network
fetch(request)
.then( responseFromFetch => {
  // 3. create a copy of the file and cache it
  let copy = responseFromFetch.clone();
  fetchEvent.waitUntil(
    caches.open(cacheName)
    .then( cache => {
      cache.put(request, copy);
    })
  );
  // 4. return the contents.
  return responseFromFetch;
})

If a browser (like Samsung Internet) doesn’t understand the bit where I say fetchEvent.waitUntil, then it will throw an error and execute the catch clause. That’s where I have my fifth and final step: “try looking in the cache instead, but if that fails, show the offline page”:

.catch( fetchError => {
  console.log(fetchError);
  return caches.match(request)
  .then( responseFromCache => {
    return responseFromCache || caches.match('/offline');
  });
})

Normally in this kind of situation, I’d use feature detection to check whether a browser understands a particular API method. But it’s a bit tricky to test for support for asynchronous waitUntil. That’s okay. I can use a try/catch statement instead. Here’s what my revised code looks like:

fetch(request)
.then( responseFromFetch => {
  let copy = responseFromFetch.clone();
  try {
    fetchEvent.waitUntil(
      caches.open(cacheName)
      .then( cache => {
        cache.put(request, copy);
      })
    );
  } catch (error) {
    console.log(error);
  }
  return responseFromFetch;
})

Now I’ve managed to localise the error. If a browser doesn’t understand the bit where I say fetchEvent.waitUntil, it will execute the code in the catch clause, and then carry on as usual. (I realise it’s a bit confusing that there are two different kinds of catch clauses going on here: on the outside there’s a .then()/.catch() combination; inside is a try{}/catch{} combination.)

At some point, when support for async waitUntil statements is universal, this precautionary measure won’t be needed, but for now wrapping them inside try doesn’t do any harm.

There are a few places in chapter five of Going Offline—the chapter about service worker strategies—where I show examples using async waitUntil. There’s nothing wrong with the code in those examples, but if you want to play it safe (especially while Samsung Internet doesn’t support async waitUntil), feel free to wrap those examples in try/catch statements. But I’m not going to make those changes part of the errata for the book. In this case, the issue isn’t with the code itself, but with browser support.

Saturday, September 1st, 2018

The Ecological Impact of Browser Diversity | CSS-Tricks

This is a terrific spot-on piece by Rachel. I firmly believe that healthy competition and diversity in the browser market is vital for the health of the web (which is why I’m always saddened and frustrated to hear web developers wish for a single monocultural rendering engine).

Tuesday, July 3rd, 2018

Cory Doctorow: Zuck’s Empire of Oily Rags – Locus Online

Facebook doesn’t have a mind-control problem, it has a corruption problem. Cambridge Analytica didn’t convince decent people to become racists; they convinced racists to become voters.

Friday, June 1st, 2018

A cartoon intro to DNS over HTTPS – Mozilla Hacks – the Web developer blog

This is a great illustrated explanation of how DNS resolution works.

Tuesday, May 29th, 2018

Scripting News: The Internet is going the wrong way

The Internet is a place for the people, like parks, libraries, museums, historic places. It’s okay if corporations want to exploit the net, like DisneyLand or cruise lines, but not at the expense of the natural features of the net.

Saturday, May 19th, 2018

The Slow Death of Internet Explorer and the Future of Progressive Enhancement · An A List Apart Article

Oliver Williams makes the case—and shows the code—for delivering only HTML to old versions of Internet Explorer, sparing them from the kind of CSS and JavaScript that they can’t deal with it. Seems like a sensible approach to me (assuming you’re correctly building in a layered way so that your core content is delivered in markup).

Rather than transpiling and polyfilling and hoping for the best, we can deliver what the person came for, in the most resilient, performant, and robust form possible: unadulterated HTML. No company has the resources to actively test their site on every old version of every browser. Malfunctioning JavaScript can ruin a web experience and make a simple page unusable. Rather than leaving users to a mass of polyfills and potential JavaScript errors, we give them a basic but functional experience.

Saturday, April 28th, 2018

An Apology for the Internet — From the People Who Built It

A hand-wringing, finger-pointing litany of hindsight, published with 11 tracking scripts attached.

  1. Start With Hippie Good Intentions …
  2. … Then mix in capitalism on steroids.
  3. The arrival of Wall Streeters didn’t help …
  4. … And we paid a high price for keeping it free.
  5. Everything was designed to be really, really addictive.
  6. At first, it worked — almost too well.
  7. No one from Silicon Valley was held accountable …
  8. … Even as social networks became dangerous and toxic.
  9. … And even as they invaded our privacy.
  10. Then came 2016.
  11. Employees are starting to revolt.
  12. To fix it, we’ll need a new business model …
  13. … And some tough regulation.
  14. Maybe nothing will change.
  15. … Unless, at the very least, some new people are in charge.

Wednesday, April 18th, 2018

The Untold Story of Jaime Levy, Punk-Rock Cyber-Publishing Pioneer

This excerpt from Claire L. Evans’s new book Broad Band sounds like Halt and Catch Fire, but for real.

Many people saw the web for the first time in Jaime’s loft, on a Mac II her hacker friend Phiber Optik set up with a 28.8K internet connection. As avant-garde guitarist Elliott Sharp performed live, and another friend, DJ Spooky, played house tracks, Jaime’s guests gathered around the Mac’s small screen. At the top of 1994, there were fewer than 1,000 websites in the world, mostly personal home pages. These converts would call themselves the “early true believers,” counting the year of their arrival online as a mark of status, the way the first punks claimed 1977.

Thursday, April 5th, 2018

Dear Developer, The Web Isn’t About You | sonniesedge.co.uk

This is absolutely brilliant!

Forgive my excitement, but this transcript of Charlie’s talk is so, so good—an equal mix of history and practical advice. Once you’ve read it, share it. I want everyone to have the pleasure of reading this inspiring piece!

It is this flirty declarative nature makes HTML so incredibly robust. Just look at this video. It shows me pulling chunks out of the Amazon homepage as I browse it, while the page continues to run.

Let’s just stop and think about that, because we take it for granted. I’m pulling chunks of code out of a running computer application, AND IT IS STILL WORKING.

Just how… INCREDIBLE is that? Can you imagine pulling random chunks of code out of the memory of your iPhone or Windows laptop, and still expecting it to work? Of course not! But with HTML, it’s a given.

Wednesday, March 28th, 2018

Who Does She Think She Is?

The internet does not hate women. The internet doesn’t hate anyone, because the internet, being an inanimate network, lacks the capacity to hold any opinion whatsoever. People hate women, and the internet allows them to do it faster, harder, and with impunity. It’s developed into a form of relaxation after a hard day of being ground on the wheel of late-stage capitalism. Melvin Kranzberg’s statement that “technology is neither good nor bad, nor is it neutral” holds true here: The internet lets us be whoever we were before, more efficiently, with fewer consequences.

Monday, February 26th, 2018

The Internet Isn’t Forever

A terrific piece by Maria Bustillos on digital preservation and the power of archives, backed up with frightening real-world examples.

Because history is a fight we’re having every day. We’re battling to make the truth first by living it, and then by recording and sharing it, and finally, crucially, by preserving it. Without an archive, there is no history.

Monday, February 19th, 2018

We need to an internet of unmonetisable enthusiasms | WIRED UK

Russell Davies:

That’s the web I want; a place with spare corners where un-monetisable enthusiasms can be preserved, even if they’ve not been updated for seven years.

Friday, February 16th, 2018

Finding the Exhaust Ports | Jon Gold’s blog

Perhaps when Bush prophesied lightning-quick knowledge retrieval, he didn’t intend for that knowledge to be footnoted with Outbrain adverts. Licklider’s man-computer symbiosis would have been frustrated had it been crop-dusted with notifications. Ted Nelson imagined many wonderfully weird futures for the personal computer, but I don’t think gamifying meditation apps was one of them.

The Good Room – Frank Chimero

Another brilliant talk from Frank, this time on the (im)balance between the commercial and the cultural web.

Remember: the web is a marketplace and a commonwealth, so we have both commerce and culture; it’s just that the non-commercial bits of the web get more difficult to see in comparison to the outsized presence of the commercial web and all that caters to it.

This really resonates with me:

If commercial networks on the web measure success by reach and profit, cultural endeavors need to see their successes in terms of resonance and significance.

Monday, February 12th, 2018

047: The Web is Neither Good or Bad…nor is it Neutral. It’s an Amplifier with Jeremy Keith – User Defenders podcast : Inspiring Interviews with UX Superheroes.

This podcast interview I did went on for quite and while and meanders all over the place, but it sure was a lot of fun. I’ve huffduffed it, and so can you. Hope you like it.

Wednesday, February 7th, 2018

Resilience: Building a Robust Web That Lasts by Jeremy Keith—An Event Apart video on Vimeo

This is the rarely-seen hour-long version of my Resilience talk. It’s the director’s cut, if you will, featuring an Arthur C. Clarke sub-plot that goes from the telegraph to the World Wide Web to the space elevator.

Resilience: Building a Robust Web That Lasts by Jeremy Keith—An Event Apart video

Sunday, January 21st, 2018

Book - Broad Band — Claire L. Evans

Coming to a bookshelf near you in March 2018: the untold story of the women who made the internet.

Wednesday, January 10th, 2018

Legends of the Ancient Web

An absolutely fantastic talk (as always) from Maciej, this time looking at the history of radio and its parallels with the internet (something that Tom Standage touched on his book, Writing On The Wall). It starts as a hobbyist, fun medium. Then it gets regulated. Then it gets used to reinforce existing power structures.

It is hard to accept that good people, working on technology that benefits so many, with nothing but good intentions, could end up building a powerful tool for the wicked.

Tuesday, January 9th, 2018

The internet doesn’t suck - Mark Surman

We need to keep our eyes on the prize: making sure the internet does not suck for as many people as possible for as long as possible. That’s the work we need to be doing. And we should do it not from a place of fear or despair, but from a place of joy.