Find out why client-side web storage is a great addition to your Angular 2 application, as well as the basics on when to use it and its limitations.
- [Instructor] Storing data in the browser is also called client-side storage, and takes advantage of a user's device to store data inside the browser used to interact with your web application. The up-side of client-side storage is very fast retrieval times, because there's no need for network connections, which means your app can be used offline. The down-side is relatively small storage space, usually less that 50 Megabytes total depending on which storage option you use. Client-side storage is also device-dependent.
If a user switches devices, clears their browser cache, upgrades or reinstalls the browser, their data will disappear. There are seven ways to store data client-side, but for most applications, you'll only make use of two or three of these options. The options I use most often in my work are web storage and URL manipulation. Web storage has a 10 Megabyte storage limit and can only store strings. There's also no built-in option for asynchronous execution, which may affect performance when working with large data sets.
That said, web storage is available across all modern browsers and has a very easy API, making it a great choice for integration into an existing application. URLs are just strings of text easily accessed by your users, which makes them easy to copy and paste across social media, via email, or in between browsers. URL manipulation is a great choice if your users are sharing links and bookmarks, and the API lets you easily squeeze a lot of data into a very small amount of space.
- Overview of data storage options
- Saving and retrieving data from the browser
- Setting routes in the URL
- Using query strings and fragments instead of routes
- Saving and retrieving data from a server
- Working with user input
- Using JSONP instead of HTTP
- Why writing custom services is important
- Writing custom services for working with browsers and servers