meumobi / infomobi

Ionic2 Employee App
3 stars 2 forks source link

caching images #287

Open vdias38 opened 5 years ago

vdias38 commented 5 years ago
vdias38 commented 5 years ago

imgcache.js is not well supported and not seems to be a future-proof way.

vdias38 commented 5 years ago
$ npm install --save ionic-image-loader

Import IonicImageLoader on home module

On /pages/home/home.html replace

<img src="./assets/images/header-clean.png" class="logo" alt="infomobi">

By <img-loader [src]="settings.logoUrl" fallbackUrl="./assets/images/header-clean.png" fallbackAsPlaceholder="true" useImg [imgAttributes]="imageAttributes"></img-loader> OR set by default settings.logoUrl = "./assets/images/header-clean.png" Where

  1. Include the ImageAttribute model in your .ts import { ImageAttribute } from 'ionic-image-loader'
  2. Generate an array of ImageAttribute objects
    const imageAttributes: ImageAttribute[] = [];
    imageAttributes.push({
    element: 'class',
    value: 'logo'
    })
vdias38 commented 5 years ago

to allow PWA caching we should define an url pattern

How to cache images using service worker

By default any images under ./assets are cached by angular sw

Should add a new AssetGroup to cache uploads img from meumobi

, {
    "name": "uploads",
    "installMode": "lazy",
    "updateMode": "lazy",
    "resources": {
      "urls": [
        "/uploads/**"
      ]
    },
  "cacheConfig": {
        "maxSize": 250,
        "maxAge": "7d"
      }