I’m using Caddy 0.10.10 on Windows 10 Pro with a small
static website. I want to use a Service Worker so the
site can run offline.
There is a problem with the redirects from
<path>/ which Caddy does
302 redirects. Using a Service Worker
data for both paths is saved, which is annoying and
wasteful. I can’t find any way to avoid the double hit.
Is there any chance of making the redirect a configurable
option in future versions of Caddy?
If you know which paths are frequently being hit twice, you can specify them as manual 301 redirects:
redir /index.html / 301
redir /some/path/index.html /some/path/ 301
As for modifying the behaviour of the static fileserver, you’ll want to submit a feature request at https://github.com/mholt/caddy/issues.
Thanks for the reply. The problem is more with the Service Worker (or my understanding of it) than Caddy. You have to provide a set of paths to be offline, and the default behaviour is to follow redirects and scoop up the data. So for the file
foo/index.html there would be three copies for
foo/index.html. I could make a Caddy-specific Service Worker which did what you’re suggesting in the service worker, but I’d need something different on other platforms. I guess I thought that a static website should be able to have a single service worker for all server platforms.
I’m interested to know whether anyone else has had SW problems and has thought of a solution…
Sorry, I’ve got no experience at all with Service Workers. From your original post I’d assumed that the issue was that Caddy gave 302s rather than 301s, so the Caddyfile snippet I gave simply configures Caddy to give 301s instead.
Could you clarify exactly what you want Caddy to do in an ideal setup?
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.