Advice generator app

Solution retrospective
Advice generator 'bug'
I didn't know why I couldn't generate a new advice after I click the button in less than a second.
It is due to the API documentation. I couldn't find exactly where it says but ChatGPT says that in older versions it used to say in the landing page of the API "Advice is cached for 2 seconds to prevent overloading the service."
How did I fix this?
The API has automatic caching in the browser (via Cache-Control headers) which means that if you request /advice again in less than a few seconds, it will return the same response (to save traffic).
So to force each request to be new, you can add a random query param by adding ?timestamp=${Date.now()} to "fool" the cache. So your API request should be like the following:
(`https://api.adviceslip.com/advice?timestamp=${Date.now()}`)
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Fernando Pérez's solution.
Join 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