angularcachingbrowser-cacheservice-workerweb-storage

Caching/Saving generated files with Angular (Service Worker or other ways)


I have some problem with my Angular service worker. I get generated PDF-Files from a Webservice. After I get them, I need to cache them, so that I can use them offline.

My first approach of thinking about this was to tell the manifest to cache the folder, where I put these files. But I can't find any way to do this. There must be an attribute like icons, where I can put a folder.

If I put a PDF-File into my assets-folder, the PDF-File won't be cached, just all other files in the folder.

The Files are to big for IndexedDb, localstorage, ..

I just need a way to save the PDFs for printing them later in the program. I'm open to any solution.


Solution

  • Service Workers cannot cache Response for POST requests. If your web service could return PDFs for GET requests, the Cache API should be available to your Service Worker for storing/caching the PDF Response. The web service may need to send header Content-Disposition: inline, so experiment a little with that.