When does tensorflow.js fetch model again instead of using cached files?


I checked some tfjs examples, and noticed that the page loads the model.json and weight files for the first time. Later if I refresh the page, the browser uses cached model.json, weight files and so on. So I would love to know if the model is updated, will the browser get the latest model automatically? If so, how does it work or how to make it work?

@Jason might be able to help here

Welcome to the TensorFlow.js community! That is a great question :slight_smile: So in the web world on the server side you can set in the header of the http response when you deliver the file how long to cache for and the rules for caching.

When the file changes on the server side the browser can see that the file has changed (without the need to download the whole file to check) and invalidate the local cached copy to force a new download. Some resources are available here on this topic if of interest:

And then also ETag:

A more friendly read of the above can be found here:

Along with this write up:

That being said, TensorFlow.js will use the browser cache detailed above (not local storage) unless you forcefully use the API to save the model to local storage I believe, and if you use local storage it is up to you to resave new files if you find new versions are available. The save API is here:

Hope that helps!