This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

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

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨апрель 2018 г.⁩.

Примечание: Эта возможность доступна в 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

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

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