vanilla-jet 1.5.2 → 1.5.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 CHANGED
@@ -4,6 +4,22 @@ 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.5.3] - 2026-06-28
8
+
9
+ ### Changed
10
+
11
+ - **Static compression now applies to ALL compressible assets, not just the app bundle.**
12
+ `framework/router.js` negotiates `.br`/`.gz` for any `css`/`js` request that has a precompressed
13
+ sibling (falling back to the original otherwise) — previously only `vanilla.min.js`/`app.min.css`.
14
+ This makes self-hosted vendor libraries serve gzip/brotli instead of uncompressed.
15
+ - `scripts/compress_br.js` now walks `public/scripts`, `public/styles`, `public/pages` and emits
16
+ `.gz` + `.br` for every `.js`/`.css`/`.html` (was: only three named files).
17
+
18
+ ### Why
19
+
20
+ - Self-hosting third-party libs (to cut CDN origins) only helps if they're served compressed;
21
+ otherwise a large lib (e.g. a 369 KB bundle) would ship uncompressed and regress vs the CDN.
22
+
7
23
  ## [1.5.2] - 2026-06-28
8
24
 
9
25
  ### Added
@@ -199,7 +199,11 @@ class Router {
199
199
  getStaticCandidates(request, ext, filename) {
200
200
  let obj = this;
201
201
  let candidates = [{ filename: filename, contentEncoding: '' }];
202
- let isCompressible = obj.compressionMimes.includes(ext) && obj.compressionFiles.includes(path.basename(filename));
202
+ // Any compressible type can be served precompressed; resolveFirstAvailableStaticFile
203
+ // falls back to the original when a .br/.gz sibling doesn't exist. This lets ALL
204
+ // self-hosted assets (vendor libs, plugins, …) be served gzip/brotli, not just the
205
+ // app bundle — otherwise self-hosting a large lib would ship it uncompressed.
206
+ let isCompressible = obj.compressionMimes.includes(ext);
203
207
  if (!isCompressible) {
204
208
  return candidates;
205
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-jet",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "VannilaJet framework",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,6 +1,8 @@
1
- // Brotli-precompresses the build outputs so the server can negotiate `.br`
2
- // (smaller than gzip). Safe + additive: the framework only serves `.br` when the
3
- // client sends `Accept-Encoding: br`; otherwise it falls back to `.gz`/original.
1
+ // Precompresses build outputs to .gz + .br so the server can serve any self-hosted
2
+ // asset (vendor libs, plugins, bundles, styles, pages) compressed via Accept-Encoding
3
+ // negotiation. Without this, self-hosting a large library would ship it uncompressed.
4
+ // Safe + additive: clients that don't accept br get gzip; those that accept neither
5
+ // get the original (resolveFirstAvailableStaticFile falls back).
4
6
 
5
7
  const fs = require('fs');
6
8
  const path = require('path');
@@ -14,33 +16,44 @@ function processCwd() {
14
16
  }
15
17
 
16
18
  const root = processCwd();
19
+ const DIRS = ['public/scripts', 'public/styles', 'public/pages'];
20
+ const COMPRESSIBLE = new Set(['.js', '.css', '.html']);
21
+ const BROTLI_OPTIONS = { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11 } };
17
22
 
18
- // Same files the framework negotiates `.br` for (router static + response.render).
19
- const TARGETS = [
20
- 'public/scripts/vanilla.min.js',
21
- 'public/styles/app.min.css',
22
- 'public/pages/home.html'
23
- ];
24
-
25
- const BROTLI_OPTIONS = {
26
- params: {
27
- [zlib.constants.BROTLI_PARAM_QUALITY]: 11,
28
- [zlib.constants.BROTLI_PARAM_SIZE_HINT]: 0
23
+ function walk(dir, out) {
24
+ let entries;
25
+ try {
26
+ entries = fs.readdirSync(dir, { withFileTypes: true });
27
+ } catch (err) {
28
+ return;
29
+ }
30
+ for (const entry of entries) {
31
+ const full = path.join(dir, entry.name);
32
+ if (entry.isDirectory()) {
33
+ walk(full, out);
34
+ } else if (
35
+ COMPRESSIBLE.has(path.extname(entry.name)) &&
36
+ !entry.name.endsWith('.gz') &&
37
+ !entry.name.endsWith('.br')
38
+ ) {
39
+ out.push(full);
40
+ }
29
41
  }
30
- };
42
+ }
43
+
44
+ const files = [];
45
+ DIRS.forEach((dir) => walk(path.join(root, dir), files));
31
46
 
32
- TARGETS.forEach((relativePath) => {
33
- const filePath = path.join(root, relativePath);
47
+ let count = 0;
48
+ files.forEach((file) => {
34
49
  try {
35
- const stats = fs.statSync(filePath);
36
- if (!stats.isFile()) {
37
- return;
38
- }
39
- const input = fs.readFileSync(filePath);
40
- const compressed = zlib.brotliCompressSync(input, BROTLI_OPTIONS);
41
- fs.writeFileSync(filePath + '.br', compressed);
42
- console.log(`VanillaJet - brotli: ${relativePath}.br (${input.length} -> ${compressed.length} B)`);
50
+ const input = fs.readFileSync(file);
51
+ fs.writeFileSync(file + '.gz', zlib.gzipSync(input, { level: 9 }));
52
+ fs.writeFileSync(file + '.br', zlib.brotliCompressSync(input, BROTLI_OPTIONS));
53
+ count = count + 1;
43
54
  } catch (err) {
44
- // File not present (feature not built yet) skip silently.
55
+ // Skip unreadable files; never fail the build over compression.
45
56
  }
46
57
  });
58
+
59
+ console.log(`VanillaJet - precompressed ${count} assets (.gz + .br)`);