码迷,mamicode.com
首页 > Web开发 > 详细

[PWA] Cache JSON Data in a React PWA with Workbox, and Display it while Offline

时间:2018-12-28 22:22:45      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:with   rate   register   class   first   from   []   erro   display   

We can view the PWA offline because we are caching the static and CDN assets for the app - but the list of todo items won‘t display, because those API calls are not being cached. We‘ll add another route to the service worker, to store the result of any .json API call from our server. Then, we‘ll be able to view the app with the entire list of items offline.

 

When we want to cache json file from our server:

workbox.skipWaiting();
workbox.clientsClaim();

workbox.routing.registerRoute(
    new RegExp(‘https:.*min\.(css|js)‘),
    workbox.strategies.staleWhileRevalidate({
        cacheName: ‘cdn-cache‘
    })
  )

// Cache the json files from our server
// for both production and dev ‘/‘
  workbox.routing.registerRoute(
    new RegExp(‘/.*:4567.*\.json‘),
    workbox.strategies.networkFirst()
  )

workbox.precaching.precacheAndRoute(self.__precacheManifest || [])

 

[PWA] Cache JSON Data in a React PWA with Workbox, and Display it while Offline

标签:with   rate   register   class   first   from   []   erro   display   

原文地址:https://www.cnblogs.com/Answer1215/p/10192902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!