MODX Shield is a two-in-one plugin that protects your site from two common MODX issues that can overload the server, waste disk space, and hurt SEO:
✅ SafeTV — prevents fatal errors when $modx->resource is missing
✅ Disable404Cache — stops caching of 404 pages entirely
Works in both standard chunks and Fenom templates, requires no external services, and is safe for shared hosting.
| ❌ Problem | 💥 Impact |
|---|---|
Calling TVs when $modx->resource is missing |
Fatal errors, broken pages |
| 404 pages cached like normal content | Thousands of duplicate cache files |
| Cache bloat from bots & invalid URLs | Increased disk usage, slower site |
| SEO pollution from indexed 404s | Lower search rankings |
| Higher hosting bills (Railway, Vercel, etc.) | Wasted storage & bandwidth |
| ✅ Feature | 🚀 Benefit |
|---|---|
SafeTV — safely handles missing $modx->resource |
No fatal errors, stable templates |
| Empty return for missing TVs | Clean output without breaking layout |
| Detects 404 by error_page ID & HTTP code | 100% reliable detection |
| Disables cache for 404s | Stops duplicate cache creation |
| Automatic cleanup of existing 404 cache files | Frees disk space instantly |
| Reduces disk I/O | Faster page loads and better hosting efficiency |
- In MODX: Go to Elements → Plugins → Create.
- Name it MODX Shield — SafeTV & 404 Cache Killer.
- Paste the plugin code from this repository.
- Enable events:
OnWebPageInitOnLoadWebDocumentOnWebPagePrerender
- Save → Clear MODX cache → Done! 🎉
After installing:
- 🚀 No more TV-related errors in chunks/Fenom
- 🗑 Immediate stop to 404 cache bloat
- ⚡ Faster site performance due to reduced disk usage
- 📉 Lower hosting bills on usage-based platforms
- 🛡 Stable, SEO-friendly MODX setup
| Component | Details |
|---|---|
| Language | PHP 7.0+ |
| CMS | MODX Revolution |
| Hosting | Works on shared, VPS, or cloud |
| Cache Control | Built-in MODX + custom logic |
| Compatibility | Chunks, Snippets, Fenom templates |
| 404 Detection | error_page ID + HTTP status code |
MIT — free to use and modify.