serwist icon indicating copy to clipboard operation
serwist copied to clipboard

How Can I cache resources from my application to have complete offline feature?

Open elVengador opened this issue 1 year ago • 1 comments

I'm implementing a complete offline application, I dont want to display a fallback page when there is not internet I want to cache all my files .html, .js, .css, .png, and font families When there is not internet I want my application check the cache and use it

That set up was posible in an old version of NextJs with next-pwa, but now I'm updating my application and I want to use serwist

Thanks in advance 🙏

elVengador avatar Apr 28 '24 01:04 elVengador

Here are blogs related to caching:

  • https://serwist.pages.dev/docs/serwist/guide/precaching

  • https://serwist.pages.dev/docs/serwist/runtime-caching

  • https://serwist.pages.dev/docs/serwist/core/serwist

Well, seems that you want to precache some files. I notice that you use Next.js, so there's a few things to keep in mind:

  • If you want to precache some pages, fonts, and images, you will have to use additionalPrecacheEntries. This option expects you to generate revision yourself, which is quite a pain, but I guess you can simply create an utility function that can hash a file's content. Hopefully we can improve this field a bit. One thing to keep in mind is that it is not recommended that you precache server-side rendered pages since they will then always be served by the precache rather than the network until the service worker is updated so that said pages should not be precached.

  • @serwist/next precaches all CSS and JavaScript files for you out of the box unless you use exclude, excludeChunks, include, or includeChunks.

  • Don't think about precaching HTML files 💀 With how Next.js does its things, you just can't get a proper list of HTML files to precache.

Also, next time, please use GitHub Discussions if you want to ask a question. Our Issues is only meant for bugs and feature requests.

DuCanhGH avatar Apr 28 '24 03:04 DuCanhGH

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 29 '24 02:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 12 '24 02:06 github-actions[bot]