Skip to content

Commit 137f154

Browse files
committed
feat: add proxy_cache for Plausible script using /dev/shm
- Use /dev/shm for cache storage (Heroku tmpfs, survives dyno restarts) - Cache Plausible script for 5 minutes - Add X-Cache header for debugging cache hits/misses - Update proxy_cache_path to 10m zone, 100m max size
1 parent ae07616 commit 137f154

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

config/nginx.conf.erb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ http {
99
charset utf-8;
1010
server_tokens off;
1111

12+
# Proxy cache using /dev/shm (tmpfs, survives dyno restarts)
13+
proxy_cache_path /dev/shm/jscache levels=1:2 keys_zone=jscache:10m inactive=30d use_temp_path=off max_size=100m;
14+
1215
# Security headers (set at http level to apply to all responses)
1316
add_header X-Frame-Options "SAMEORIGIN" always;
1417
add_header X-Content-Type-Options "nosniff" always;
@@ -53,12 +56,18 @@ http {
5356
return 444;
5457
}
5558

56-
# Plausible: Proxy script.js
59+
# Plausible: Proxy script.js (with caching)
5760
location = /js/script.js {
5861
proxy_pass $plausible_script_url;
5962
proxy_set_header Host plausible.io;
6063
proxy_pass_header Cache-Control;
6164
proxy_buffering on;
65+
66+
# Cache for 5 minutes
67+
proxy_cache jscache;
68+
proxy_cache_valid 200 5m;
69+
proxy_cache_use_stale updating error timeout invalid_header http_500;
70+
add_header X-Cache $upstream_cache_status;
6271
}
6372

6473
# Plausible: Proxy event API

0 commit comments

Comments
 (0)