# A programmatic PWA (service worker) module

**URL:** <https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611>\
**Category:** New theme/module\
**Tags:** modules, pwa\
**Created:** [March 25, 2023, 5:53pm UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611 "2023-03-25T17:53:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [March 25, 2023, 5:53pm UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/1 "2023-03-25T17:53:02Z")

</div>

Hi, I just finished my [PWA module](https://github.com/hugomods/pwa) and it’s [docs](https://hugomods.com/en/docs/pwa/), you may be interested in it.

## Features

- Offline available: offline page and offline image.
- Installable: can be added to home screen.
- Precaching: allow precaching pages, CSS, JS, fonts and so on.
- Cache Strategies[1](https://hugomods.com/en/docs/pwa/#fn:1): supports cache first, network first and stale while revalidate.

You can preview it via the video below, the [real site](https://hugomods.com/) and the [demo site](https://hugomods.github.io/pwa/).

[![](https://img.youtube.com/vi/gvMkLiNlnl8/maxresdefault.jpg "Hugo PWA Module Preview") ](https://www.youtube.com/watch?v=gvMkLiNlnl8)

---

<div class="post-metadata">

**Author:** ![iaeiou](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/iaeiou/32/15332_2.png) [@iaeiou](https://discourse.gohugo.io/u/iaeiou)\
**Post date:** [March 27, 2023, 7:04am UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/2 "2023-03-27T07:04:40Z")

</div>

Awesome, thanks!

Are you able to cache external files, like images / JS assets hosted on a separate server?

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [March 27, 2023, 10:45am UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/3 "2023-03-27T10:45:36Z")

</div>

Currently, external files were ignored to be cached (but preaches works with external files). I have an idea how to configure which origin’s assets can be cached, and make it configurable by users, this feature is planned.

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [March 27, 2023, 3:32pm UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/4 "2023-03-27T15:32:05Z")

</div>

I added this feature into `v0.2.1`, you could preview it on the [demo site](https://hugomods.github.io/pwa/), users can control which origins are trusted, only the same origin (base URL) is trusted by default.

Screenshot on offline.

![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/2/6/2607b78d3a8924940fba60f0c16bb3022beff45f.png)

---

<div class="post-metadata">

**Author:** ![iaeiou](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/iaeiou/32/15332_2.png) [@iaeiou](https://discourse.gohugo.io/u/iaeiou)\
**Post date:** [March 27, 2023, 8:09pm UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/5 "2023-03-27T20:09:53Z")

</div>

This. is. awesome. Thanks!

---

<div class="post-metadata">

**Author:** ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)\
**Post date:** [March 28, 2023, 3:55am UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/6 "2023-03-28T03:55:22Z")

</div>

@idarek How does this compare to your PWA method? I remember you had something I haven’t had a chance to look at yet.

[Simple implementation of PWA on a website with a Mobile First Design approach – Dariusz Więckiewicz 🇬🇧 (wieckiewicz.org)](https://dariusz.wieckiewicz.org/en/simple-implementation-pwa-webdev-mobile-first-design/)

---

<div class="post-metadata">

**Author:** ![idarek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/idarek/32/26229_2.png) [@idarek](https://discourse.gohugo.io/u/idarek)\
**Post date:** [March 28, 2023, 4:43am UTC](https://discourse.gohugo.io/t/a-programmatic-pwa-service-worker-module/43611/7 "2023-03-28T04:43:02Z")

</div>

On my list to have a look on that 😉 just need to find a bit of time…
