- Client side caching greatly improve single page application performance, even if only caching for a few minutes.
- Not always clear how to implement caching fur RxJS observable results in an abstract, reusable way
- Demonstrates how to implement a local storage and cache service that is RxJS fluent to allow chaining with Angular Http library
- When used with Service Workers, it can help you achieve offline capable applications
A common need in a production ready single page web applications is browser caching of API responses in order to speed up page load time and reduce overall API “chattiness”. When implemented successfully and used in conjunction with Service Workers, you can achieve offline capable web apps (Service Workers can cache APIs too, but are typically more useful for resource caching such as HTML, Images, JS, CSS, etc).
The need for client side caching is especially true for application that start from entirely stateless hosting (i.e. no server side, such as when hosting from an AWS S3 bucket), since all dynamic data has to be fetched on page load, even if the page was refreshed seconds ago. Caching data in the browser, even for a few minutes, can vastly improve the user experience.
Caching API responses is nothing new, but since Angular 2+ uses RxJS for its
Http API, its not clear how to achieve client caching in an abstract way that can be reused across different types of requests.
Continue reading →