This is the second step to getting your app to load live data.
We're still not going to call out to the server . First we're going to load from a cache.
Doing it this way means we won't hit the request limit on your server during development (which is good!)
Understand Local Storage
The browser has a sort of built in database called Local Storage. This allows you to save data for your website, so if the user closes the browser, data can be restored next time.
Change your dataLoader function to return data from LocalStorage. The means when you do dataLoader('fixtures'), you return the fixture data saved in local storage, not from a local variable.
In your data-loader.js file, when you import your data from a file, save it to local storage under the correct name
import fixture data from fixture data json
set fixture data as an item called "fixtures" in local storage
now your app is:
Populating local storage with pre-loaded data when it loads
This is the second step to getting your app to load live data.
We're still not going to call out to the server . First we're going to load from a cache.
Doing it this way means we won't hit the request limit on your server during development (which is good!)
Understand Local Storage
The browser has a sort of built in database called Local Storage. This allows you to save data for your website, so if the user closes the browser, data can be restored next time.
Take a look at MDN's docs on Web Storage (web storage is Local Storage, I think they renamed it) https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage
Use web storage
We're going to cheat, first off all.
dataLoader('fixtures')
, you return the fixture data saved in local storage, not from a local variable.now your app is:
Neat.