Remove non-TLS support
This commit is contained in:
1 parent
84c07a912b
commit
b59ef914da
9 files changed
+88
-171
No files matched your search
+10
-27
@@ -1,7 +1,7 @@
|
||||
// Page startup.
|
||||
//
|
||||
// Pages arrive whole -- composed by the service worker, or by boot.html on the
|
||||
// visit before there is one -- so there is nothing here that builds a page.
|
||||
// Pages arrive whole -- the service worker composes every one of them -- so
|
||||
// there is nothing here that builds a page.
|
||||
// What is left is the three things a composed document cannot do for itself:
|
||||
// put a swapped-in page where it belongs before it is painted, land the
|
||||
// reference picker where the reader asked to go, and tell the chrome when a
|
||||
@@ -94,11 +94,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
// A worker-composed page is an ordinary document and the browser scrolls to
|
||||
// the anchor itself. One composed by boot.html is not: it replaced a
|
||||
// document the browser had already finished with, so the fragment identifier
|
||||
// has been spent. Repeating it costs nothing in the first case and is what
|
||||
// makes a link to GEN#v1_1 land on the verse in the second.
|
||||
// The browser scrolls to the anchor itself on a document it navigated to,
|
||||
// so this is for the one it does not: a reload that landed on boot.html and
|
||||
// was reloaded again into the real page. Costs nothing when the browser has
|
||||
// already been there.
|
||||
function scrollToHash() {
|
||||
var el = hashTarget();
|
||||
if (el) jumpTo(el);
|
||||
@@ -166,25 +165,12 @@
|
||||
//
|
||||
// Toggling the class rather than the style because Bootstrap declares
|
||||
// .d-none !important, which an inline display would lose to.
|
||||
//
|
||||
// Only the digest line is missing on a page boot.html composed -- there was
|
||||
// no worker to name a version -- so the element itself is always here.
|
||||
function showVersion() {
|
||||
var el = document.getElementById('app-version');
|
||||
if (!el) return;
|
||||
el.classList.toggle('d-none', !document.querySelector('#content .index'));
|
||||
}
|
||||
|
||||
// api/bookmark has no origin server -- it is answered by the worker -- so
|
||||
// there is nothing to ask until the worker is controlling this page.
|
||||
// controller, not ready: ready can resolve a tick before clients.claim()
|
||||
// takes effect, and a request sent in that gap reaches the network and 404s.
|
||||
function whenControlled(fn) {
|
||||
if (!('serviceWorker' in navigator)) return;
|
||||
if (navigator.serviceWorker.controller) return fn();
|
||||
navigator.serviceWorker.addEventListener('controllerchange', fn, { once: true });
|
||||
}
|
||||
|
||||
// Deferred scripts run before DOMContentLoaded fires, so this always lands,
|
||||
// and it lands after htmx has processed the shell.
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
@@ -192,15 +178,12 @@
|
||||
showVersion();
|
||||
|
||||
// Registered from the page it is going to serve, not from a page of its
|
||||
// own: there is nothing to wait for and nothing to reload. This load is
|
||||
// already the real app -- the worker installs alongside it, and takes over
|
||||
// composing, the bookmark and the offline download from the next
|
||||
// navigation on.
|
||||
// own: this load is already the real app, composed by the worker that is
|
||||
// controlling it. What this catches is the copy on disk having changed
|
||||
// since -- the browser refetches sw.js, sees different bytes, and installs
|
||||
// the new one alongside, which takes over from the next navigation on.
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('sw.js').catch(function () {});
|
||||
}
|
||||
whenControlled(function () {
|
||||
document.body.dispatchEvent(new CustomEvent('worker-ready'));
|
||||
});
|
||||
});
|
||||
})();
|
||||
+16
-19
@@ -1,17 +1,15 @@
|
||||
// The renderer, shared by the two things that ever build a page: the service
|
||||
// worker, which composes every navigation once it is installed, and boot.html,
|
||||
// which composes the one navigation that arrives before there is a worker to
|
||||
// do it.
|
||||
// The renderer: the templates in templates/, and the two things sw.js does
|
||||
// with them -- compose a fragment into the shell, and stand a notice in for a
|
||||
// page that could not be delivered.
|
||||
//
|
||||
// Sharing it is the whole point. A shell only the worker could build is what
|
||||
// made a first visit show a spinner and reload; with the same templates and
|
||||
// the same code reachable from the page, the first visit is already the app
|
||||
// and the worker is what makes the second one fast and the hundredth one
|
||||
// offline.
|
||||
// A file of its own rather than more of sw.js because it is the half with
|
||||
// nothing to do with the network: no routes, no caches, no requests. It was
|
||||
// loaded by boot.html as well once, which composed pages in the browser for a
|
||||
// device that could not install a worker; nothing but the worker builds a page
|
||||
// now.
|
||||
//
|
||||
// Loaded as a plain script by both -- importScripts in the worker, a <script>
|
||||
// tag in the page -- so it defines a global rather than exporting. Nunjucks
|
||||
// must already be loaded.
|
||||
// Loaded with importScripts, so it defines a global rather than exporting.
|
||||
// Nunjucks must already be loaded.
|
||||
(function (scope) {
|
||||
'use strict';
|
||||
|
||||
@@ -123,10 +121,9 @@
|
||||
//
|
||||
// chrome is what the shell needs and the fragment cannot carry: the
|
||||
// bookmark, the navbar picker's model, and the two versions the worker
|
||||
// was built with. All three are null from boot.html, which has no worker
|
||||
// to ask for any of them; the first two render as a hidden slot that
|
||||
// fills itself if one ever appears, and the third renders as nothing,
|
||||
// because no worker is the whole of what there is to report.
|
||||
// was built with. reference is null on the book list, which is the
|
||||
// picker's hidden state; the other two are always there, because the
|
||||
// worker composing this is the thing that knows them.
|
||||
compose: function (fragment, chrome) {
|
||||
var title = (TITLE_RE.exec(fragment) || ['', ''])[1].trim();
|
||||
var content = fragment.replace(TITLE_RE, '');
|
||||
@@ -134,9 +131,9 @@
|
||||
return render(name, {
|
||||
title: title,
|
||||
content: content,
|
||||
mark: (chrome && chrome.mark) || null,
|
||||
reference: (chrome && chrome.reference) || null,
|
||||
version: (chrome && chrome.version) || null
|
||||
mark: chrome.mark,
|
||||
reference: chrome.reference,
|
||||
version: chrome.version
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user