Design comparison
Solution retrospective
Hello, I have a bug when I click quickly, the advice doesn't update right away. If you have a solution please tell me :)
Thank you,
Ornella
Community feedback
- @IpieAPosted over 1 year ago
Hey Ornella, great work. I just worked on this too.
So, the API documentation says "Advice is cached for 2 seconds. Any repeat-request within 2 seconds will return the same piece of advice." That's probably why quick clicks won't update immediately, but after 2 seconds
To get past this, you can generate a random query parameter and append to the API URL to bypass the caching mechanism. This is what I mean:
const timestamp = Date.now(); const res = await fetch(
https://api.adviceslip.com/advice?timestamp=${timestamp}
);It tricks the API server to think that it is a new request each time. I hope this helps
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