Глобальное свойство caches

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Примечание: Эта возможность доступна в Web Workers.

Доступное только для чтения глобальное свойство caches возвращает объект CacheStorage связанный с текущим контекстом. С помощью этого объекта можно реализовать хранение ресурсов в автономном режиме и генерацию индивидуальных ответов на запросы.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Значение

Объект CacheStorage.

Примеры

Данный пример показывает как использовать кеш в контексте service worker для хранения в автономном режиме.

js
this.addEventListener("install", (event) => {
  event.waitUntil(
    caches
      .open("v1")
      .then((cache) =>
        cache.addAll([
          "/",
          "/index.html",
          "/style.css",
          "/app.js",
          "/image-list.js",
          "/star-wars-logo.jpg",
          "/gallery/",
          "/gallery/bountyHunters.jpg",
          "/gallery/myLittleVader.jpg",
          "/gallery/snowTroopers.jpg",
        ]),
      ),
  );
});

Спецификации

Specification
Service Workers
# self-caches

Совместимость с браузерами

Смотрите также