How To Read Files With JavaScript And FileReader
Analysing files in PHP is easy. But what if you want to access the content of a file without the overhead of sending it to a server first (e.g. for displaying a thumbnail before uploading an image)?
JavaScript provides a neat little API to achieve just that. It’s called FileReader. Let’s find out what it can do!
How To Build A Live Chat With WebSockets
WebSockets are a fascinating technology, a TCP-based network protocol that allows for asynchronous bi-directional communication. The client starts a connection, sends a request and gets a response – just like HTTP. But much unlike HTTP this connection is kept alive! This has many advantages, like
- Faster responses (no re-establishing connections)
- Less trafic (no overhead for HTTP-headers)
- Live updates (no periodic polling, but push notifications)
If you want to learn more about WebSockets, I recommend this introduction. In this post we’re focussing on utilizing WebSockets to build a simple chat application.
How To Detect Swipes In JavaScript
When working on my reverse engineering of 2048 for browsers I wanted it to be playable on mobile devices as well. Problem was, that while you could perfectly use your keyboard to control the tile movement on a desktop, this was not possible on smartphones! Digging through the web I found some partially working solutions but nothing quite good. So I decided to craft it myself and the results work flawlessly!
Hello Progressive Web App | Caching Strategies
This is the last part of the series “Hello Progressive Web App”.
Table of Contents
- Introduction
- Manifest
- Service Worker
- Caching Strategies
- Debugging
There are a bunch of caching strategies out there. Here are two of them that I found particularly useful:
Cache Then Network Then Cache
|
|
What this does is it first checks if the request is already cached. If so, the cached version is returned. If not, it goes to the network to fetch it. On success it puts the response in the cache and returns it to the browser. Note that we have to clone the response as it can be consumed only once.
Hello Progressive Web App | The Manifest
This is part 2 of the series “Hello Progressive Web App”.
Table of Contents
The manifest of a web app is a JSON file which provides information about that app. Here’s an example of a basic manifest.json
:
|
|
Most of the attributes are self explanatory. The ‘start_url’ defines where the application lives. Relative parts in this attribute start from the manifest’s location. Setting ‘display’ to ‘standalone’ means that when launching the app from the homescreen it will look like a native app. If you want your app to open in a browser, you may set ‘display’ to ‘browser’. All the possible attributes are described in more detail here.
Hello Progressive Web App | The Service Worker
This is part 3 of the series “Hello Progressive Web App”.
Table of Contents
- Introduction
- Manifest
- Service Worker
- Caching Strategies
- Debugging
A service worker is a type of web worker. Its job is to intercept network requests, cache files, retrieve those files from cache and deliver push messages.