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.
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.
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).
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With