Tells to the plugin what to cache and how.
'all'
: means that everything (all the webpack output assets) and URLs listed inexternals
option will be cached on install.Object
: Object with 3 possible sections (properties) of typeArray<string>
:main
,additional
,optional
. All sections are optional and by default are empty (no assets added).
Default:
'all'
.
Pass an Object
to caches
option to manually specify how to cache build assets.
Example:
caches: {
main: [':rest:'],
additional: [':externals:'],
optional: ['*.chunk.js']
}
In this example assets which ends with .chunk.js
are added to optional
cache, external assets added to additional
cache and rest of the assets are added to main
cache.
Use special keyword :rest:
to match all unused/uncached assets. To match multiple assets or assets with dynamic names, use pattern matching. To add external assets (from outside of your webpack build), list them in externals
option and then user :externals:
keyword in caches
. If you don't want to put all externals
into the same section, you can list those assets manually (e.g. additional: ['/external.js']
) instead of using :externals:
keyword.
main
: Assets listed in this section are cached first (oninstall
event inServiceWorker
) and if caching of this section fails -- no assets are cached at all. Hence, it should contain most important set of assets (for example['index.html', 'main.js']
), without which your website won't work.additional
: By default enabled only inServiceWorker
. Assets in this section are loaded aftermain
section is successfully loaded (onactivate
event in ServiceWorker). If any of assets fails to download, then nothing is cached from theadditional
section and all the assets are moved to theoptional
section. If current update strategy ischanged
, then only failed to download assets are moved to theoptional
section, all other are successfully cached.optional
: By default enabled only inServiceWorker
. Assets in this sections are cached only when they are fetched from the server.ServiceWorker
won't download them ahead of time.
Note: AppCache doesn't support conditional or delayed assets loading and by default ignores assets in
additional
andoptional
sections. To make AppCache cache all sections, set this option:
AppCache: {
caches: ['main', 'additional', 'optional']
}