Design comparison
Solution retrospective
Currently, I hard coded in a wait time (about 1.5 seconds) between button click by disabling the random button, because repeatedly clicking it doesn't seem to update the quote (the function is called when I tested it.) Is it the APIs' limitation, or the way I implemented the fetch method?
Thanks in advance for taking a look at the project!
Community feedback
- @SkidragonPosted over 2 years ago
Hi Yingyi, good job on completing the project! It's kind of a combination of the browser and the API. The API wants to cache the advice for 2 seconds on the server to save extra db calls plus the server will use less resources and most modern browsers wants to cache data as much as possible since its cheaper to get data from the browser rather than browser -> server -> database -> server -> browser. They might be only using redis (key,value) store and might not need a seperate database.
Calling with the same URL might make the browser store the URL as a key and the data as the value { URL: data }. So the solution I did was put a new Date() generated timestamp query param at the end of my URL: https://api.adviceslip.com/advice?timestamp=1647571215979. Last thing, the advice container doesn't need a media query, using width: 100%; and max-width: 40rem or something will do the trick instead of vw. Anyway I did wish they would send to the UI how long they will cache things to disable the button on the UI for the period.
Marked as helpful0@yingmo55Posted over 2 years ago@Skidragon Thank you for the detailed explanation on how the API works and feedback on the media queries!
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord