Chapter 19. Closing Thoughts

Introduction

I hope you’ve found the recipes and APIs covered in this book to be useful and interesting. Hopefully you’ve been able to apply what you’ve learned in this book to level up your JavaScript applications.

In Defense of Third-Party Libraries

One of the main themes of this book is the fact that you can do so much without needing third-party libraries. This is true, but don’t feel like you have to avoid third-party libraries at all costs. Sometimes using the built-in browser APIs saves you from needing a dependency, but you might have to write extra “glue” code to adapt it to what you’re trying to accomplish.

Some browser APIs can be awkward to work with. Take the IndexedDB API, for example. It’s a powerful data persistence and access layer, but its API is callback based and can be painful to work with. There are libraries available that wrap IndexedDB and provide a simpler—or, in some cases, more powerful—API. For example, Dexie.js wraps IndexedDB with a Promise-based API.

In the end, everything is a trade-off. If you have room to spare in your JavaScript bundle to provide an easier developer experience, it’s probably worth it.

Detect Features, Not Browser Versions

If you need to check if the user is running a browser that supports the API you want to use, you might think to look at the user agent string and figure out which browser version the user has. Try to avoid this. It is notoriously unreliable, plus it’s trivial to spoof the user ...

Get Web API Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.