Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 8 months ago

Advice generator app

vite, vue, tailwind-css
Fernando Pérez•480
@fermop
A solution to the Advice generator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What challenges did you encounter, and how did you overcome them?

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()}`)
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community 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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License