arthur installs as an app, and keeps what projects load
A manifest and icons make it installable. A service worker at /sw.js, so its scope is every page, keeps by kind of URL: content-addressed blobs and blocks for good, as projects load them; the versioned bundle and styles until the next build; and the last copy of the page, the API reads and other statics, for when there is no network. A project opened once opens again offline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011FLuCjp9kNH6ovwJVXSbq9
This commit is contained in:
parent
bbe20b3abf
commit
f0af8d392a
9 changed files with 172 additions and 1 deletions
|
|
@ -37,7 +37,7 @@ from django.contrib.auth import login as auth_login, logout as auth_logout
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.http import FileResponse, HttpResponse, JsonResponse
|
||||
from django.http import FileResponse, Http404, HttpResponse, JsonResponse
|
||||
from django.shortcuts import render
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
|
|
@ -146,6 +146,22 @@ def page(request, project_id=None, slug=None):
|
|||
})
|
||||
|
||||
|
||||
def service_worker(request):
|
||||
"""`static/arthur/sw.js`, at the root of the site.
|
||||
|
||||
A service worker controls only the paths under where it is served from, and
|
||||
a project is `/p/<id>`, so `/static/arthur/sw.js` would control nothing that
|
||||
matters. Never cached itself: a browser compares this file to decide whether
|
||||
there is a new worker, so a stale copy would keep the old one for good."""
|
||||
for root in settings.STATICFILES_DIRS:
|
||||
path = Path(root) / "arthur" / "sw.js"
|
||||
if path.exists():
|
||||
response = HttpResponse(path.read_bytes(), content_type="application/javascript")
|
||||
response["Cache-Control"] = "no-cache"
|
||||
return response
|
||||
raise Http404("no service worker")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the detector
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue