lavas-project / jekyll-pwa

Jekyll plugin for PWA
MIT License
107 stars 19 forks source link

Images Not Caching #5

Open mswbull opened 6 years ago

mswbull commented 6 years ago

Great plugin, this is exactly what I need for my use case!

Everything is working as designed, however the Service Worker does not cache images embedded within the posts (it does cache heading images).

Is this by design or am I missing something? Any help would be greatly appreciated?

xiaoiver commented 6 years ago

I think there're two options to cache images with Google Workbox:

  1. use precache_glob_patterns, you can add the filepath of images into the regexp so that they can be precached. But if there're too many images to precache, the installation of service-worker will take a lot of time. So I think only precaching some critical images seems like a better choice.
  2. use runtime_cache to cache images embedded within every post in runtime.

I think you can treat different images with different strategies:

precache_glob_patterns:
    - "{js,css,fonts}/**/*.{js,css,eot,svg,ttf,woff}"
    - index.html
    - "my-critical-image/path/*.{png,jpg}"
runtime_cache:
    - route: /img\/embedded\/within\/my\/post
      strategy: cacheFirst