I wrote an article explaining - step by step - how to inject PWA features into an Angular project.
You can read more here.
As it has already being suggested, you can use service workers to cache assets.
If you run the following command in the CLI ( Angular add schematics):
ng add @angular/pwa
It will setup almost everything for you (you can find all the details in my article at the link above).
By default the command above will cache all files in the asset
folder with a lazy strategy (that means they will be cached after they have been requested at least once).
Below the generated file:
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch", <- Those files are cached immediately by the SW
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "lazy", <- Those files are cached after a first request
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
If you want to provide those images eagerly and make them available even if the user is offline, you can set installMode: prefetch
in the config file that the previous command creates for you (ngsw-config.json).
With this you would be able to deliver the images from the cache and you can also set a lifetime.
In the article I also describe how to cache API GET Requests, if you want to further improve your app.