jekyll-pwa icon indicating copy to clipboard operation
jekyll-pwa copied to clipboard

Images Not Caching

Open mswbull opened this issue 7 years ago • 1 comments

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?

mswbull avatar Feb 02 '18 15:02 mswbull

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

xiaoiver avatar Feb 06 '18 02:02 xiaoiver