vanilla-jet 1.6.0 → 1.6.2
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 +30 -0
- package/framework/router.js +11 -1
- package/framework/server.js +1 -0
- package/package.json +1 -6
- package/scripts/compile_html.js +20 -0
- package/test/router.test.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,36 @@ All notable project changes are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format follows a structure inspired by Keep a Changelog and semantic versioning.
|
|
6
6
|
|
|
7
|
+
## [1.6.2] - 2026-06-30
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **Template externalization now self-cleans:** disabling `externalize_templates` (or never enabling it)
|
|
12
|
+
removes any previously generated `public/scripts/templates.js` (+ `.gz`/`.br`), so toggling the flag
|
|
13
|
+
never leaves a stale 749 KB file behind (which the service worker would otherwise precache).
|
|
14
|
+
|
|
15
|
+
### Notes
|
|
16
|
+
|
|
17
|
+
- **`externalize_templates` caveat (WebView):** it shrinks the initial HTML for web browsers, but it injects
|
|
18
|
+
all templates via one synchronous `innerHTML`. On slower JS engines (native WebViews — WKWebView /
|
|
19
|
+
Android WebView) that block can stall the boot. **Prefer it OFF for apps loaded primarily inside a
|
|
20
|
+
WebView**; keep it ON only for pure-web apps that benefit from a smaller first byte.
|
|
21
|
+
|
|
22
|
+
## [1.6.1] - 2026-06-29
|
|
23
|
+
|
|
24
|
+
### Security
|
|
25
|
+
|
|
26
|
+
- **Removed unused dependencies that carried known vulnerabilities:** `jsrsasign` (multiple high/critical
|
|
27
|
+
crypto advisories), `jwt-simple`, `blueimp-md5`, `js-beautify`, and `nodemon`. None were used by the
|
|
28
|
+
framework; this drops a large vulnerability + install-size footprint for consumers.
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- **`settings.profile.static_cache_max_age`** (seconds, default `0`): sets `Cache-Control: public, max-age=N`
|
|
33
|
+
for NON-versioned static assets (images, fonts, animation JSON…), so they are reused across references
|
|
34
|
+
and reloads instead of revalidating every time. Versioned (`?v=`) assets stay `immutable`; `0` keeps the
|
|
35
|
+
previous `no-cache` behavior. Pairs with the service worker for clients without it (e.g. WebViews).
|
|
36
|
+
|
|
7
37
|
## [1.6.0] - 2026-06-29
|
|
8
38
|
|
|
9
39
|
### Added
|
package/framework/router.js
CHANGED
|
@@ -46,6 +46,10 @@ class Router {
|
|
|
46
46
|
this.compressionFiles = [ 'vanilla.min.js', 'app.min.css' ];
|
|
47
47
|
this.enablePrecompressedNegotiation = Boolean(server?.options?.enable_precompressed_negotiation);
|
|
48
48
|
this.enableServiceWorker = Boolean(server?.options?.enable_service_worker);
|
|
49
|
+
// Cache-Control max-age (seconds) for NON-versioned static assets (images, fonts,
|
|
50
|
+
// animation JSON…). Lets the browser reuse them across references/reloads instead of
|
|
51
|
+
// revalidating each time. Versioned (?v=) assets stay immutable; 0 keeps no-cache.
|
|
52
|
+
this.staticCacheMaxAge = Number(server?.options?.static_cache_max_age) || 0;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
routeToRegExp(route) {
|
|
@@ -284,6 +288,7 @@ class Router {
|
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
buildStaticHeaders(extHeader, candidates, contentEncoding, metadata, isImmutable) {
|
|
291
|
+
let obj = this;
|
|
287
292
|
let staticHeaders = Object.assign({}, extHeader);
|
|
288
293
|
if (contentEncoding) {
|
|
289
294
|
staticHeaders['Content-Encoding'] = contentEncoding;
|
|
@@ -300,8 +305,13 @@ class Router {
|
|
|
300
305
|
// This is the big win for clients without the service worker (e.g. native WebViews),
|
|
301
306
|
// which otherwise revalidate every asset on every load.
|
|
302
307
|
staticHeaders['Cache-Control'] = 'public, max-age=31536000, immutable';
|
|
308
|
+
} else if (obj.staticCacheMaxAge > 0) {
|
|
309
|
+
// Non-versioned assets (images, fonts, animation JSON…): cache for a while so they
|
|
310
|
+
// aren't re-fetched on every reference/reload. ETag/Last-Modified still allow a cheap
|
|
311
|
+
// 304 after expiry. Pick this when assets change rarely (e.g. a few days/weeks).
|
|
312
|
+
staticHeaders['Cache-Control'] = `public, max-age=${obj.staticCacheMaxAge}`;
|
|
303
313
|
} else {
|
|
304
|
-
//
|
|
314
|
+
// Default: force revalidation to keep clients fresh without a hard reload.
|
|
305
315
|
staticHeaders['Cache-Control'] = 'no-cache, must-revalidate';
|
|
306
316
|
}
|
|
307
317
|
return staticHeaders;
|
package/framework/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vanilla-jet",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "VannilaJet framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,14 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/nalancer08/VanillaJet#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"blueimp-md5": "2.19.0",
|
|
34
33
|
"chalk": "4.1.2",
|
|
35
34
|
"html-minifier-terser": "7.2.0",
|
|
36
|
-
"js-beautify": "1.15.4",
|
|
37
|
-
"jsrsasign": "11.1.0",
|
|
38
|
-
"jwt-simple": "0.5.6",
|
|
39
35
|
"minimist": "1.2.8",
|
|
40
|
-
"nodemon": "3.1.10",
|
|
41
36
|
"nunjucks": "3.2.4",
|
|
42
37
|
"underscore": ">= 1.12.x",
|
|
43
38
|
"del": "^6.0.0",
|
package/scripts/compile_html.js
CHANGED
|
@@ -201,6 +201,10 @@ async function createHTMLFile(content, filePath) {
|
|
|
201
201
|
// bundle (defer + document order), so views still find their templates in the DOM at boot.
|
|
202
202
|
if (opts.externalize_templates) {
|
|
203
203
|
minified = externalizeTemplates(minified);
|
|
204
|
+
} else {
|
|
205
|
+
// Feature off: remove any previously generated templates.js so a stale 749KB file
|
|
206
|
+
// isn't left behind (and isn't precached by the service worker).
|
|
207
|
+
removeStaleTemplatesFile();
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
const publicPath = path.join(processCwd(), '/public/pages');
|
|
@@ -218,6 +222,22 @@ async function createHTMLFile(content, filePath) {
|
|
|
218
222
|
console.log(chalk.green(`Created gzipped version at: ${absolutePath}.gz`));
|
|
219
223
|
}
|
|
220
224
|
|
|
225
|
+
// -- Remove a previously generated public/scripts/templates.js (+ compressed siblings)
|
|
226
|
+
// when externalization is disabled, so toggling the flag never leaves a stale file behind.
|
|
227
|
+
function removeStaleTemplatesFile() {
|
|
228
|
+
const base = path.join(processCwd(), 'public', 'scripts', 'templates.js');
|
|
229
|
+
['', '.gz', '.br'].forEach((ext) => {
|
|
230
|
+
try {
|
|
231
|
+
if (fs.existsSync(base + ext)) {
|
|
232
|
+
fs.unlinkSync(base + ext);
|
|
233
|
+
console.log(chalk.green(`VanillaJet - removed stale public/scripts/templates.js${ext}`));
|
|
234
|
+
}
|
|
235
|
+
} catch (err) {
|
|
236
|
+
// Non-fatal: never fail the build over cleanup.
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
221
241
|
// -- Move all <script type="text/template"> blocks out of the page into
|
|
222
242
|
// public/scripts/templates.js (a tiny injector that adds them to the DOM). Returns the
|
|
223
243
|
// page HTML with those blocks replaced by a single deferred <script> tag (placed where the
|
package/test/router.test.js
CHANGED
|
@@ -48,6 +48,18 @@ test('isProtectedFile: blocks framework/external/node_modules and top-level file
|
|
|
48
48
|
assert.equal(router.isProtectedFile('/public/scripts/vanilla.min.js'), false);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
test('buildStaticHeaders: immutable for ?v=, max-age when configured, else no-cache', () => {
|
|
52
|
+
const meta = { size: 10, etag: 'W/"x"', lastModified: 'Mon, 01 Jan 2024 00:00:00 GMT' };
|
|
53
|
+
const plain = makeRouter();
|
|
54
|
+
assert.match(plain.buildStaticHeaders({}, [], '', meta, true)['Cache-Control'], /immutable/);
|
|
55
|
+
assert.match(plain.buildStaticHeaders({}, [], '', meta, false)['Cache-Control'], /no-cache/);
|
|
56
|
+
|
|
57
|
+
const cached = new Router({ options: { static_cache_max_age: 3600 } });
|
|
58
|
+
assert.match(cached.buildStaticHeaders({}, [], '', meta, false)['Cache-Control'], /max-age=3600/);
|
|
59
|
+
// Versioned still wins over max-age.
|
|
60
|
+
assert.match(cached.buildStaticHeaders({}, [], '', meta, true)['Cache-Control'], /immutable/);
|
|
61
|
+
});
|
|
62
|
+
|
|
51
63
|
test('mimes: serves common web fonts and icons', () => {
|
|
52
64
|
const router = makeRouter();
|
|
53
65
|
assert.equal(router.mimes['woff2'], 'font/woff2');
|