D3:如何关闭JSON文件?

时间:2023-01-24 10:56:17

When I update the contents of a JSON file they are not changed when I access them with d3.json. I suspect it may be necessary to CLOSE the file in order to refresh the contents but so far I have been unable to find how to do that. (I rename the file and that works but clearly that is not desirable.)

当我更新JSON文件的内容时,当我使用d3.json访问它们时,它们不会改变。我怀疑可能有必要关闭文件以刷新内容,但到目前为止我还无法找到如何做到这一点。(我重命名了这个文件,它可以工作,但显然这是不可取的。)

1 个解决方案

#1


1  

You're seeing this behaviour because of your browser caching the JSON. That is, when you reload the page, the browser doesn't actually request the JSON again. Here's what you can do.

您看到这种行为是因为浏览器缓存JSON。也就是说,当重新加载页面时,浏览器实际上不会再次请求JSON。这是你能做的。

  • Delete the browser cache or close and reopen the browser.
  • 删除浏览器缓存或关闭并重新打开浏览器。
  • Add a query parameter (which won't do anything) to the file name, see this question.
  • 向文件名添加一个查询参数(它什么都不做),请参见这个问题。
  • Rename the file (as you've discovered already).
  • 重命名文件(正如您已经发现的)。
  • If you have control over the webserver, you can configure it to prevent caching. See the answers to the question I've linked to above for more details.
  • 如果您控制了webserver,您可以配置它来防止缓存。有关更多细节,请参见上面链接的问题的答案。

#1


1  

You're seeing this behaviour because of your browser caching the JSON. That is, when you reload the page, the browser doesn't actually request the JSON again. Here's what you can do.

您看到这种行为是因为浏览器缓存JSON。也就是说,当重新加载页面时,浏览器实际上不会再次请求JSON。这是你能做的。

  • Delete the browser cache or close and reopen the browser.
  • 删除浏览器缓存或关闭并重新打开浏览器。
  • Add a query parameter (which won't do anything) to the file name, see this question.
  • 向文件名添加一个查询参数(它什么都不做),请参见这个问题。
  • Rename the file (as you've discovered already).
  • 重命名文件(正如您已经发现的)。
  • If you have control over the webserver, you can configure it to prevent caching. See the answers to the question I've linked to above for more details.
  • 如果您控制了webserver,您可以配置它来防止缓存。有关更多细节,请参见上面链接的问题的答案。