Reputation: 5055
I have created an image slider. To fetch next and previous images I have created 2 functions.
component.ts:
ngOnInit(){
this.length = this.images.length; }
getNextImage(){
this.imageUrl = '';
this.imageIndex++;
if (this.imageIndex< this.length){
this.imageUrl = this.images[this.imageIndex]
}
}
getPreviousImage(){
this.imageUrl = '';
this.imageIndex++;
if (this.imageIndex>= 0){
this.imageUrl = this.images[this.imageIndex]
}
}
Every time I click on previous and next buttons the image downloads again.
Is there a way that if image is already downloaded once then it can be saved in cache?
Is this only possible with service worker?
Upvotes: 1
Views: 241
Reputation: 26362
Another option as decribed in this stack overflow question, would be to use Application Cache
Upvotes: 1