It persists until you tell it not to — again, you have full control.
Note: The Cache API is not supported in every browser.
Now for a real example — what if we wanted to load images dynamically, but we wanted to make sure the images were loaded before we tried to display them?
This is a standard thing to want to do, but it can be a bit of a pain.
It is different in the following ways: This registers a service worker, which runs in a worker context, and therefore has no DOM access.
It uses a promise-powered function to read image data from a JSON object and load the images using Ajax, before displaying the images in a line down the page. It also registers, installs, and activates a service worker, and when more of the spec is supported by browsers it will cache all the files required so it will work offline!But the overriding problem is that there still isn’t a good overall control mechanism for asset caching and custom network requests.The previous attempt — App Cache — seemed to be a good idea because it allowed you to specify assets to cache really easily.We can use , but it’s still not foolproof, and what about multiple images?And, ummm, it’s still synchronous, so blocks the main thread.