Here comes Part 2 of this series. You can read more about this project’s background on the project’s page. Or start from the beginning with part 1

Random Quote – Part 2 – Vanilla JavaScript and JSON: Using various front end stacks

submited by
Style Pass
2021-07-22 11:30:07

Here comes Part 2 of this series. You can read more about this project’s background on the project’s page. Or start from the beginning with part 1 of this series.

If you’re curious about the next flavors and would like to make a writer very happy today, you should subscribe to Morse Wall.

There is a very limited number of quotes in the array used in flavor #1. Still, one has to scroll down quite a bit to get to see functional code. In real life, data is typically stored somewhere else, many times in someone else’s server, as JSON, XML, CSV, SQL, etc.

In flavor #2, the data is stored in a JSON file hosted together with the rest of the code. There are only 3 quotes in the code snippet from quotes.json below (so I can illustrate the point), but many more quotes in the JSON in production.

In order to fetch that data, I’m using the fetch() method. fetch() is asynchronous code, i.e. when executed, it won’t pause the execution of the rest of the code.

Leave a Comment