Gathering detailed insights and metrics for ionic-cache-src
Gathering detailed insights and metrics for ionic-cache-src
Gathering detailed insights and metrics for ionic-cache-src
Gathering detailed insights and metrics for ionic-cache-src
npm install ionic-cache-src
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Ionic module for caching resources, works for any HTML tag, use storage and filesystem. Uses Ionic Storage so it supports IndexedDB, SQLite (Cordova), WebSQL
As Directive (html) change src
to cacheSrc
1<img cacheSrc="http://sample-videos.com/img/Sample-png-image-1mb.png"/>
1<div cacheSrc="http://sample-videos.com/img/Sample-jpg-image-500kb.jpg"></div>
1<video cacheSrc="http://sample-videos.com/video/mp4/240/big_buck_bunny_240p_1mb.mp4"></video>
You can use a preload image while the resource is downloading. It works for any tag. By default it uses a predefined image.
1<img [cacheSrc]="IMAGE_URL" [preImage]="PRELOAD_IMAGE_PATH" />
Via NPM
1$ npm install --save ionic-cache-src @ionic/storage --save
or Yarn
1$ yarn add ionic-cache-src @ionic/storage
IonicCacheSrcModule
in your module:1import { NgModule } from '@angular/core'; 2import { IonicStorageModule } from '@ionic/storage'; 3import { File } from '@ionic-native/file'; 4import { FileTransfer } from '@ionic-native/file-transfer'; 5 6import { IonicCacheSrcModule } from 'ionic-cache-src'; 7 8@NgModule({ 9 imports: [ 10 ... 11 IonicStorageModule.forRoot(), 12 IonicCacheSrcModule 13 ], 14 providers: [ 15 File, 16 FileTransfer, 17 ... 18 ] 19}) 20export class YourModule {};
Make sure to install the following ionic modules and cordova plugins:
Your typescript file. Use cache
or cacheAll
methods to fetch resources. (Note: Just first time, resource is downloaded and saved in filesystem)
1import { Component } from '@angular/core'; 2import { CacheSrcService } from 'ionic-cache-src'; 3 4@Component({ 5 selector: 'home-page', 6 templateUrl: 'home.html' 7}) 8export class HomePage { 9 10 let paths: string[] = []; 11 12 constructor(private _cacheSrv: CacheSrcService) { 13 let images = [ 14 'http://sample-videos.com/img/Sample-png-image-500kb.png' 15 'http://sample-videos.com/img/Sample-png-image-1mb.png' 16 'http://sample-videos.com/img/Sample-jpg-image-500kb.jpg' 17 ]; 18 19 // Use cache() for one resource 20 this._cacheSrv.cacheAll(images) 21 .subscribe(cacheItems => { 22 this.paths = cacheItems.map(item => item.path); 23 }); 24 } 25 26}
Your html file
1<img *ngFor="let path of paths" [cacheSrc]="path"/>
If not exists, saves a resource in storage and filesystem, otherwise, returns the saved item.
Param | Type | Description |
---|---|---|
url | string | URL of the server to download the file, as encoded by encodeURI(). |
Gets a list of resources and evaluates which of them not exists in storage and filesystem and starts download. Otherwise, returns all the saved items.
Param | Type | Description |
---|---|---|
urls | string[] | List of URLs of the server to download the file, as encoded by encodeURI(). |
Returns a value of the first item in storage and filesystem that satisfies the provided url. Otherwise null is returned.
Param | Type | Description |
---|---|---|
url | string | URL of the server to download the file, as encoded by encodeURI(). |
Removes any item associated with this url. Returns the deleted item with status "deleted".
Param | Type | Description |
---|---|---|
url | string | URL of the server to download the file, as encoded by encodeURI(). |
Clears the entire ionic-cache-src storage and filesystem. Returns a list of items with status 'deleted'.
Param | Type | Description |
---|---|---|
url | string | URL from where it was downloaded. |
key | string | Name of the saved file. |
path | string | File path of the saved resource. |
status | string | Shows "incomplete" while resource is downloading, "complete" once it is saved. |
This module works with Ionic Framework (v >= 2.0), the supported platforms being:
If you find this project useful, please star the repo to let people know that it's reliable. Also, share it with friends and colleagues that might find this useful as well. Thank you :smile:
No vulnerabilities found.
No security vulnerabilities found.