Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should i cache manifest.json in service worker

I am using service worker. Should I cache my manifest.json file. Does it makes sense? Also how frequently does the browser fetch this file.

like image 875
aWebDeveloper Avatar asked Aug 02 '17 14:08

aWebDeveloper


People also ask

Should I cache service worker?

Caching unnecessary resources wastes bandwidth and storage space and could cause your app to serve unintended outdated resources. You don't need to cache all the assets at once, you can cache assets many times during the lifecycle of your PWA, such as: On installation of the service worker. After the first page load.

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 should manifest json be located?

First check if manifest. json is applied in the browser. For that open developer window by pressing shortcut F12. In Application tab, click Manifest option and see if it displays information that you have set.

What should be included in manifest json?

Using manifest. json , you specify basic metadata about your extension such as the name and version, and can also specify aspects of your extension's functionality (such as background scripts, content scripts, and browser actions).


2 Answers

Yes you should cache your manifest.json file, because if you a building a PWA, then it must have a functionality to Add to home screen. In your manifest file, it contains a start_url that needs to be cached by service worker and should return a 200 response when offline.

Let's assume anyone is offline browsing your app and hasn't added the web app on home screen, then it will ask user if he/she wants to add to home screen or not provided you have cached your manifest file.

like image 64
Mohit Bajoria Avatar answered Sep 19 '22 14:09

Mohit Bajoria


It is called at every page load (assuming that its not an SPA). Its also static anyway, might as well cache it in my opinion saves the trouble of calling the server for that file.

like image 21
oninross Avatar answered Sep 18 '22 14:09

oninross