How can I cache the image in ionic3


#1

I have a ionic3 app that contain a lot of images for display, and I discover a huge data usage problem. So I had search a solution for reduce the data usage.
I have find this plugin https://www.npmjs.com/package/ionic-image-loader, but not working in iOS, and many peoples said it is because WKwebview & CORS.
Any suggestion for this, thanks a lot.


#2

Use a Service Worker: https://robferguson.org/blog/2018/04/16/0ptimising-the-performance-of-an-ionic-pwa-part-1/


#3

I am using img tag and each image is a URL and render the image in the app, how the service worker help to reduce the data consumption of data plan of mobile?


#4

ngsw-config.json

Now we’re ready to create our service worker configuration file:

...

      "urls": [
        "https://fonts.googleapis.com/**"
      ]

...

Use a Service Worker: https://robferguson.org/blog/2018/04/16/0ptimising-the-performance-of-an-ionic-pwa-part-1/


#5

This is the part where I’m bit confused. Can I fully utilize a service worker inside Cordova built “native” app on iOS? … as regarding to the original request from @Nulra


#6

No, but then again @Nulra didn’t mention ‘Cordova’ or ‘Hybrid Mobile App’ in his post.


#7

sorry, I am doing a hybrid mobile app.


#8

Then your best bet at this point is: Cache Image for Offline Use


#9

So the loop is closed. The link @robinyo provided points out the npm package that presumably doesn’t work in iOS which was the very root of this thread :wink: