Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Added images to cache #271

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable, unreleased changes to this project will be documented in this file.

## [Unreleased]

- Fix image caching - #271 by @timuric

## 0.5.0

- Add stock quantity check without checkout in cart page - #254 by @piotrgrundas
Expand Down
10 changes: 10 additions & 0 deletions src/components/CachedImage/CachedImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ class CachedImage extends React.Component<CachedImageProps, CachedImageState> {
}
}

addImagesToCache() {
if ("caches" in window) {
const { url, url2x } = this.props;
window.caches
.open("image-cache")
.then(cache => cache.addAll([url, url2x]));
}
}

componentDidMount() {
this.addImagesToCache();
addEventListener("offline", this.updateOnlineStatus);
addEventListener("online", this.updateOnlineStatus);
this.updateAvailability();
Expand Down