domma-cms 1.61.2 → 1.61.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/docs/cache.md +6 -0
- package/package.json +1 -1
- package/server/services/publicAssets.js +55 -6
- package/server/templates/page.html +4 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.61.3] - 2026-11-12
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- **Pictures no longer hold up a returning visitor's page.** Images, fonts, and stylesheets a script loads by its plain URL are served `Cache-Control: public, max-age=0, stale-while-revalidate=604800`: the browser shows the copy it has at once and checks for a newer one in the background. With each check slowed to 3 seconds, a repeat page load took about 90 ms in Chromium and 290 ms in Firefox, against about 3 seconds before. An edited image shows from the next view on. Scripts are left as they were.
|
|
8
|
+
- `menu-float.js` and `forms.js` are no longer linked by their own tags in the page template: `site.js` imports both, so they now come from the import map and are cached for good like the rest.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- A module imported under two URLs (`characters.mjs` and `characters.mjs?v=...`; `celebrations/index.js` from the effects runtime and the form logic) ran twice. The import map now sends every URL of one file to one target.
|
|
13
|
+
|
|
3
14
|
## [1.61.2] - 2026-11-11
|
|
4
15
|
|
|
5
16
|
- Mail: a mirrored folder catches up when it is opened, so its list matches the folder's unread count (Domma Mail core 0.24.3).
|
package/docs/cache.md
CHANGED
|
@@ -112,6 +112,12 @@ Before the response cache is asked, the route decides whether the viewer may see
|
|
|
112
112
|
|
|
113
113
|
Images are not fingerprinted: scripts draw them from data by the plain URL, and one picture under two URLs downloads twice.
|
|
114
114
|
|
|
115
|
+
Every URL of one file maps to the same target, so a module imported both as `x.mjs` and as `x.mjs?v=...` is still one instance: the URL the page's own tag loads it by when there is one, otherwise the first of its URLs, fingerprinted.
|
|
116
|
+
|
|
117
|
+
### Checked in the background
|
|
118
|
+
|
|
119
|
+
What the page cannot fingerprint - an image under `/media/`, `/public/`, Domma's dist or a plugin's `public/`, a font, or a stylesheet a script adds by its plain URL - is served `public, max-age=0, stale-while-revalidate=604800` (`REVALIDATE_IN_BACKGROUND`). The browser uses its copy straight away and revalidates it without holding up the page; an edited image (an in-place upload, the image editor's save) shows from the next view. Scripts keep `max-age=0`: a script one view out of date can break a page. The decision is made in an `onRequest` hook, so a request the Manager has already answered for another site's host keeps that site's own header.
|
|
120
|
+
|
|
115
121
|
`content/custom.css` over 4 KB is linked as `/content/custom.css` (served by the same module, compressed once per encoding) instead of being inlined; previews keep it inline, and so does a stylesheet with a relative `url()` or `@import`, which would resolve differently as a file. The hand-written `?v=` tokens stay as they are - `tests/services/asset-cache-busting.test.js` still applies.
|
|
116
122
|
|
|
117
123
|
## Listings and the per-request memos
|
package/package.json
CHANGED
|
@@ -56,6 +56,13 @@ import {createHash} from 'node:crypto';
|
|
|
56
56
|
import {encode, pickEncoding} from './htmlResponse.js';
|
|
57
57
|
|
|
58
58
|
export const IMMUTABLE = 'public, max-age=31536000, immutable';
|
|
59
|
+
/**
|
|
60
|
+
* For a file the page cannot fingerprint - an image, or a stylesheet or font a script
|
|
61
|
+
* asks for by its plain URL: the browser shows the copy it has straight away and checks
|
|
62
|
+
* for a newer one in the background (RFC 5861). The page never waits on the check, and
|
|
63
|
+
* a changed file shows from the next view on.
|
|
64
|
+
*/
|
|
65
|
+
export const REVALIDATE_IN_BACKGROUND = 'public, max-age=0, stale-while-revalidate=604800';
|
|
59
66
|
export const VERSION_PARAM = '_pv';
|
|
60
67
|
/** The URL the site's custom CSS is served at once it is too big to inline. */
|
|
61
68
|
export const CUSTOM_CSS_URL = '/content/custom.css';
|
|
@@ -63,6 +70,28 @@ export const CUSTOM_CSS_URL = '/content/custom.css';
|
|
|
63
70
|
export const CUSTOM_CSS_INLINE_MAX = 4096;
|
|
64
71
|
|
|
65
72
|
const TEXT_TYPES = new Set(['.css', '.js', '.mjs']);
|
|
73
|
+
/** Served REVALIDATE_IN_BACKGROUND when not fingerprinted. Not scripts: a script one view out of date can break a page. */
|
|
74
|
+
const BACKGROUND_TYPES = new Set([
|
|
75
|
+
'.css',
|
|
76
|
+
'.png', '.jpg', '.jpeg', '.gif', '.webp', '.avif', '.svg', '.ico', '.bmp',
|
|
77
|
+
'.woff', '.woff2', '.ttf', '.otf', '.eot'
|
|
78
|
+
]);
|
|
79
|
+
/** Where those are served from: the static mounts in server.js. */
|
|
80
|
+
const BACKGROUND_PREFIX = /^\/(?:media|public|dist\/domma|plugins\/[^/?#]+\/public)\//;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Does a request for this URL get REVALIDATE_IN_BACKGROUND? Its path is under one of the
|
|
84
|
+
* static mounts and names an image, a font or a stylesheet.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} rawUrl - the request URL as sent
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
*/
|
|
89
|
+
export function revalidatesInBackground(rawUrl) {
|
|
90
|
+
if (typeof rawUrl !== 'string') return false;
|
|
91
|
+
const pathname = rawUrl.split(/[?#]/)[0];
|
|
92
|
+
if (!BACKGROUND_PREFIX.test(pathname) || pathname.includes('..')) return false;
|
|
93
|
+
return BACKGROUND_TYPES.has(path.extname(pathname).toLowerCase());
|
|
94
|
+
}
|
|
66
95
|
|
|
67
96
|
/** @type {{root: string, dommaDist: string, pluginsDir: string, customCss: string}|null} */
|
|
68
97
|
let _roots = null;
|
|
@@ -261,10 +290,27 @@ async function importMapFor(html) {
|
|
|
261
290
|
else if (found.has(url)) rewrite.add(url);
|
|
262
291
|
}
|
|
263
292
|
if (!found.size) return none;
|
|
293
|
+
// One file, one module. Two importers that name it differently - `characters.mjs` and
|
|
294
|
+
// `characters.mjs?v=...` - would get two instances, each running its top level. So
|
|
295
|
+
// every URL for a file maps to the same target: the URL the page's own tag loads it by,
|
|
296
|
+
// when it has one, otherwise the first of its URLs, fingerprinted.
|
|
297
|
+
const fileOf = (url) => { try { return decodeURIComponent(url.split('?')[0]); } catch { return url; } };
|
|
298
|
+
const fingerprinted = (url, version) => `${url}${url.includes('?') ? '&' : '?'}${VERSION_PARAM}=${version}`;
|
|
299
|
+
/** @type {Map<string, string>} file path -> the one URL every import of it resolves to */
|
|
300
|
+
const target = new Map();
|
|
301
|
+
for (const url of [...entries].sort()) {
|
|
302
|
+
const file = fileOf(url);
|
|
303
|
+
if (target.has(file)) continue;
|
|
304
|
+
if (imported.has(url) && !found.has(url)) target.set(file, url);
|
|
305
|
+
else if (rewrite.has(url)) target.set(file, fingerprinted(url, found.get(url)));
|
|
306
|
+
}
|
|
264
307
|
const imports = {};
|
|
265
308
|
for (const url of [...found.keys()].sort()) {
|
|
266
|
-
|
|
309
|
+
const file = fileOf(url);
|
|
310
|
+
if (!target.has(file)) target.set(file, fingerprinted(url, found.get(url)));
|
|
311
|
+
if (target.get(file) !== url) imports[url] = target.get(file);
|
|
267
312
|
}
|
|
313
|
+
if (!Object.keys(imports).length) return none;
|
|
268
314
|
return {tag: `<script type="importmap">${JSON.stringify({imports}).replace(/</g, '\\u003c')}</script>`, rewrite};
|
|
269
315
|
}
|
|
270
316
|
|
|
@@ -440,20 +486,23 @@ export function registerPublicAssets(app, roots) {
|
|
|
440
486
|
}
|
|
441
487
|
|
|
442
488
|
app.decorateRequest('dmImmutableAsset', false);
|
|
489
|
+
app.decorateRequest('dmBackgroundAsset', false);
|
|
443
490
|
// Added by serve(), after the plugins, as adminAssets' is: a plugin's onRequest hook that
|
|
444
491
|
// answers a request itself (site-manager proxying another site's host) must run first, or
|
|
445
492
|
// this would judge that site's fingerprint against THIS install's files.
|
|
446
493
|
const serve = () => {
|
|
494
|
+
// Decided here, not in onSend: a request another hook has already answered (the
|
|
495
|
+
// Manager proxying a site's host) never gets this far, and keeps that site's own header.
|
|
447
496
|
app.addHook('onRequest', async (request) => {
|
|
448
497
|
if (request.method !== 'GET' && request.method !== 'HEAD') return;
|
|
449
|
-
if (!request.raw.url.includes(`${VERSION_PARAM}=`)) return;
|
|
450
498
|
if (request.raw.url.startsWith(CUSTOM_CSS_URL)) return; // its route decides for itself
|
|
451
|
-
if (await matches(request.raw.url)) request.dmImmutableAsset = true;
|
|
499
|
+
if (request.raw.url.includes(`${VERSION_PARAM}=`) && await matches(request.raw.url)) request.dmImmutableAsset = true;
|
|
500
|
+
else if (revalidatesInBackground(request.raw.url)) request.dmBackgroundAsset = true;
|
|
452
501
|
});
|
|
453
502
|
app.addHook('onSend', async (request, reply, payload) => {
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
503
|
+
if (reply.statusCode !== 200 && reply.statusCode !== 304) return payload;
|
|
504
|
+
if (request.dmImmutableAsset) reply.header('cache-control', IMMUTABLE);
|
|
505
|
+
else if (request.dmBackgroundAsset) reply.header('cache-control', REVALIDATE_IN_BACKGROUND);
|
|
457
506
|
return payload;
|
|
458
507
|
});
|
|
459
508
|
};
|
|
@@ -195,13 +195,10 @@
|
|
|
195
195
|
<!-- [image zoom] pictures' full-size view - only on a page that has one -->
|
|
196
196
|
{{imageZoomModule}}
|
|
197
197
|
|
|
198
|
-
<!-- Floating menu panels
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
<!-- Core Forms renderer -->
|
|
204
|
-
<script src="/public/js/forms.js?v=20261109-form-embed" type="module"></script>
|
|
198
|
+
<!-- Floating menu panels (menu-float.js) and the core Forms renderer (forms.js)
|
|
199
|
+
come in with site.js, which imports both: every page, whatever its navbar.
|
|
200
|
+
A tag of their own here kept them out of the import map, so a returning
|
|
201
|
+
visitor's browser asked about both on every page. -->
|
|
205
202
|
|
|
206
203
|
<!-- Core effects runtime -->
|
|
207
204
|
<script src="/public/js/effects.js?v=20261111-inline-settings" defer></script>
|