Promises

How to Cancel a Fetch Request – Website Design Article

JavaScript promises have always been a major win for the language — they’ve led to a revolution of asynchronous coding that has vastly improved performance on the web. One shortcoming of native promises is that there’s no true way to cancel a fetch…until now. A new AbortController has been added to the JavaScript specification that will allow developers to use a signal to abort one or multiple fetch calls. Here’s the flow of how canceling a fetch call works: Create…

Read More

JavaScript waitForTime – Website Design Article

I write a lot of tests for new features within Firefox DevTools. We have hundreds of “mochitests” which open the browser and perform synthetic actions like clicking, typing, and other user actions. I’ve previously written about waitForever which essentially halts following actions without locking the browser. Another utility I enjoy is waitForTime, an async JavaScript function that I can await to give breathing time between two tasks. Whenever I want to wait a given amount of time between tasks, I…

Read More

JavaScript Detect Async Function – Website Design Article

JavaScript async/await has changed the landscape of how we code. We’re no longer stuck in callback or then hell, and our code can feel more “top down” again. Async functions require the following syntax: async function myFunction() { } To use await with a function, the function needs to be declared with async. That got me to thinking: is it possible to detect if a function is asynchronous? To detect if a function is asynchronous, use the function’s constructor.name property:…

Read More

Build a Decentralized Web Chat in 15 Minutes – Website Design Article

In this 15 minute tutorial we’re going to build a simple decentralized chat application which runs entirely in a web browser. All you will need is a text editor, a web browser, and a basic knowledge of how to save HTML files and open them in the browser. We’re going to use Bugout, a JavaScript library that takes care of the peer-to-peer networking and cryptography. If you just want the files, download index.html in this repo. Ok, let’s get started! Start with the HTML boilerplate To keep…

Read More

Write Your First Service Worker in 5 Minutes – Website Design Article

What is a service worker? A service worker is a little file that will allow you to cache files and other assets on a user’s machine. How is this different from server-side caching? Because the assets are stored on a user’s machine, rather than a server, there is no need to go across a network. This offers a lot of gains for your app’s reliability and speed. Since the app is being served from a cache, there’s no need to…

Read More