xxscreeps-mod-client 0.2.8 → 0.2.10

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.
Files changed (2) hide show
  1. package/backend.js +14 -0
  2. package/package.json +2 -2
package/backend.js CHANGED
@@ -28,6 +28,18 @@ const CONTENT_TYPES = {
28
28
  '.txt': 'text/plain',
29
29
  }
30
30
 
31
+ // Vite content-hashes everything under the assets dir (_client/), so those URLs
32
+ // change whenever their content does and can be cached forever. Everything else
33
+ // (index.html, themes/, other public/ assets) keeps a stable URL across releases
34
+ // and must be revalidated so updated files (e.g. the sprite atlas) aren't served
35
+ // stale from the browser cache.
36
+ const IMMUTABLE_CACHE = 'public, max-age=31536000, immutable'
37
+ const REVALIDATE_CACHE = 'no-cache'
38
+
39
+ function cacheControlFor(filePath) {
40
+ return filePath.includes(`${path.sep}_client${path.sep}`) ? IMMUTABLE_CACHE : REVALIDATE_CACHE
41
+ }
42
+
31
43
  function readBool(envName, fallback) {
32
44
  const env = process.env[envName]
33
45
  if (env === undefined) return fallback
@@ -68,6 +80,7 @@ function sendFile(ctx, filePath, stat) {
68
80
  const ext = path.extname(filePath).toLowerCase()
69
81
  ctx.type = CONTENT_TYPES[ext] ?? 'application/octet-stream'
70
82
  ctx.lastModified = stat.mtime
83
+ ctx.set('Cache-Control', cacheControlFor(filePath))
71
84
  ctx.set('Content-Length', String(stat.size))
72
85
  ctx.body = createReadStream(filePath)
73
86
  }
@@ -90,6 +103,7 @@ function renderInjectedIndex(filePath) {
90
103
 
91
104
  function sendInjectedIndex(ctx) {
92
105
  ctx.type = 'text/html'
106
+ ctx.set('Cache-Control', REVALIDATE_CACHE)
93
107
  ctx.body = renderInjectedIndex(indexFile)
94
108
  }
95
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxscreeps-mod-client",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "xxscreeps mod that serves the screeps-client and connects it to the same server.",
5
5
  "type": "module",
6
6
  "xxscreeps": true,
@@ -23,7 +23,7 @@
23
23
  "node": ">=20"
24
24
  },
25
25
  "dependencies": {
26
- "screeps-client": "^0.6.0"
26
+ "screeps-client": "^0.7.3"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "xxscreeps": "*"