This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The has() method of the CacheStorage interface returns a Promise that resolves to true if a Cache object matches the cacheName.

Syntax

caches.has(cacheName).then(function(boolean) {
  // true: your cache exists!
});

Returns

a Promise that resolves to true if the cache exists or false if not.

Parameters

cacheName
A DOMString representing the name of the Cache object you are looking for in the CacheStorage.

Examples

The following example first checks whether a cache called 'v1' exists. If so, we add a list of assets to it. If not (meaning the has() promise would reject) then we run some kind of cache set-up function.

caches.has('v1').then(function(hasCache) {
  if (!hasCache) {
    someCacheSetupfunction();
  } else {
    caches.open('v1').then(function(cache) {
      return cache.addAll(myAssets);
    });
  }
}).catch(function() {
  // Handle exception here.
});

Specifications

Specification Status Comment
Service Workers
The definition of 'CacheStorage' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support 40Edge Full support YesFirefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR.)
IE No support NoOpera Full support 27Safari No support NoWebView Android Full support 40Chrome Android Full support 40Edge Mobile Full support YesFirefox Android Full support 44Opera Android Full support 27Safari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Last updated by: ExE-Boss,