bun-plugin-stx 0.2.102 → 0.2.104

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/dist/serve.d.ts CHANGED
@@ -17,6 +17,24 @@ export declare function buildDynamicRouteRegexes(fileRouteBase: string): RegExp[
17
17
  * `NODE_ENV=development`, so it keeps the helpful list.
18
18
  */
19
19
  export declare function isProductionServe(): boolean;
20
+ /**
21
+ * `Cache-Control` for a file served straight out of `publicDir`.
22
+ *
23
+ * Development says `no-store`, so a swapped favicon or hero image appears on
24
+ * the next reload rather than an hour later.
25
+ *
26
+ * Production does not: this server IS production for a server-rendered deploy,
27
+ * with no CDN in front stamping cache headers on the way past. Sending
28
+ * `no-store` there told every browser, proxy and link-preview crawler to
29
+ * re-fetch every image on every request, and made messengers that cache a
30
+ * preview by its headers throw the card away.
31
+ *
32
+ * An hour for ordinary assets, because they are replaced in place by a deploy
33
+ * and a share card that changed with a copy edit should not be stale for a
34
+ * year. A fingerprinted name (a content hash in it) can never change under a
35
+ * given URL, so it gets the long immutable lifetime.
36
+ */
37
+ export declare function staticCacheControl(pathname: string, production?: boolean): string;
20
38
  /**
21
39
  * Render the built-in fallback 404 page.
22
40
  *
package/dist/serve.js CHANGED
@@ -8726,6 +8726,12 @@ function isProductionServe() {
8726
8726
  const devEnvs = new Set(["development", "dev", "local", "test", "testing"]);
8727
8727
  return !(devEnvs.has(node) || devEnvs.has(app));
8728
8728
  }
8729
+ function staticCacheControl(pathname, production = isProductionServe()) {
8730
+ if (!production)
8731
+ return "no-store";
8732
+ const fingerprinted = /[.-][0-9a-f]{8,}\.[a-z0-9]+$/i.test(pathname);
8733
+ return fingerprinted ? "public, max-age=31536000, immutable" : "public, max-age=3600";
8734
+ }
8729
8735
  function render404Page(opts) {
8730
8736
  const { path, routes = [], isProduction } = opts;
8731
8737
  const baseStyles = `
@@ -10263,7 +10269,7 @@ ${pageSetupScripts.join(`
10263
10269
  return new Response(file, {
10264
10270
  headers: {
10265
10271
  "Content-Type": staticContentTypes[ext || ""] || "application/octet-stream",
10266
- "Cache-Control": "no-store"
10272
+ "Cache-Control": staticCacheControl(resolvedPath)
10267
10273
  }
10268
10274
  });
10269
10275
  }
@@ -10399,6 +10405,7 @@ if (import.meta.main) {
10399
10405
  main().catch(console.error);
10400
10406
  }
10401
10407
  export {
10408
+ staticCacheControl,
10402
10409
  serve,
10403
10410
  render404Page,
10404
10411
  isProductionServe,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.102",
4
+ "version": "0.2.104",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",