我一直在做 random quote machine freecodecamp 的项目,我似乎无法阻止正在缓存的 api 的响应。
我试过各种答案:
- fetch(), how do you make a non-cached request?
- https://forum.freecodecamp.org/t/apis-and-the-random-quote-machine-not-even-sure-what-to-ask/65982/13
我以为我曾经有过它:
fetch(this.url, {cache: 'no-cache'})
.then(res => res.json())
...但我只是在开发者工具中禁用了缓存。
请帮忙。 :-D.
这是我一直在努力让它发挥作用的地方: https://codepen.io/JonathanDWood/pen/gRNNKx
最佳答案
我已经设法通过将 Date.now()
附加到 url 来修复它。我不太喜欢将它作为永久解决方案,因为它没有解决潜在的缓存问题,但它确实有效。
fetch(this.url+ Date.now(), {cache: 'no-store'})
.then(res => res.json())
关于javascript - 获取缓存响应 - 无缓存 header 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267123/