admin管理员组

文章数量:1426048

I've been doing the random quote machine project for freecodecamp and I can't seem to stop the response from the api being cached.

I've tried various answers:

  • fetch(), how do you make a non-cached request?

I thought I had it at one point:

fetch(this.url, {cache: 'no-cache'})
    .then(res => res.json())

... but I was just disabling the cache in developer tools.

Please help. :-D.

Here is where i've been trying to make it work:

I've been doing the random quote machine project for freecodecamp and I can't seem to stop the response from the api being cached.

I've tried various answers:

  • fetch(), how do you make a non-cached request?
  • https://forum.freecodecamp/t/apis-and-the-random-quote-machine-not-even-sure-what-to-ask/65982/13

I thought I had it at one point:

fetch(this.url, {cache: 'no-cache'})
    .then(res => res.json())

... but I was just disabling the cache in developer tools.

Please help. :-D.

Here is where i've been trying to make it work: https://codepen.io/JonathanDWood/pen/gRNNKx

Share Improve this question edited Jul 24, 2017 at 0:54 Jon Wood asked Jul 23, 2017 at 16:02 Jon WoodJon Wood 1,76115 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

I have managed to fix it by appending Date.now() to the url. I don't really like it as a permanent solution as it doesn't address the underlying caching issue but it works.

fetch(this.url+ Date.now(), {cache: 'no-store'})
    .then(res => res.json())

本文标签: javascriptFetch caching responsenocache headers not working as expectedStack Overflow