Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load cdn file and save it in Service Worker

Is it possible to load website with CDN bootstrap javascript and css file and save these files into Service Worker for offline ? I would like to find out how to download file from web online and store it for offline using. I really appreciate each advice or article.

like image 875
Martin Zápotocký Avatar asked May 29 '16 22:05

Martin Zápotocký


People also ask

Can service workers access cache?

Using a Service worker you can easily set an app up to use cached assets first, thus providing a default experience even when offline, before then getting more data from the network (commonly known as Offline First).

Where do I put a Serviceworker file?

A service worker file located at /js/sw. js would only work for files in the /js directory. As a result, you should place your service worker file inside the root directory of your site.

What is service worker cache?

A service worker intercepts network-type HTTP requests and uses a caching strategy to determine what resources should be returned to the browser.

What is use of Serviceworker?

A service worker is a specific type of JS Script, which runs in the background of the user's browser. It acts like a proxy server exists between your app, the browser and the network. Among other things, service workers allow apps to continue functioning offline in case the user loses internet connection.


1 Answers

Service worker cache API does support caching for all CDN resources and you can use Cache API provides a storage mechanism for Request / Response object pairs that are cached as part of the ServiceWorker life cycle.

Infact sw-precache and sw-toolbox are the most popular Service worker caching libraries that provides common caching patterns and an expressive approach for Runtime Caching and Precaching for static resources.

More techniques outlined in the offline-cookbook to provide a robust offline experience with sensible fallbacks.

like image 196
Vivek Pratap Singh Avatar answered Oct 11 '22 15:10

Vivek Pratap Singh