Monster Full Page Cache

What is MonsterFPC v2?

  • MonsterFPC is an ultra-aggressive, high-performance static caching engine for MODX Revolution. It bypasses the standard MODX parser by dumping your fully rendered pages as pure static HTML files directly to your server's disk.
  • The logic is simple but powerful: When anonymous users visit your site, the engine serves these HTML files instantly. PHP and MySQL barely have to wake up. The result? Zero database queries for standard visits and a Time To First Byte (TTFB) in flat milliseconds.
  • Unlike other extras, MonsterFPC was built to be "surgical". Connected to OnDocFormSave, it understands exactly which page you are editing and updates only that specific cache file, leaving the rest of your site running at maximum speed.

System Settings Explained

  • Cache Lifetime (monsterfpc.cachelife): Defines how long (in seconds) a cached page remains valid. If set to 0, the cache will never expire automatically and will only be refreshed when the resource is manually updated.
  • Enable MonsterFPC (monsterfpc.enabled): The master switch. Set to 1 to activate the cache engine or 0 to disable it entirely across the site.
  • Exclude Resources (monsterfpc.exclude): A powerful filter to prevent specific pages from being cached. Enter URL patterns or extensions, such as .xml or /checkout.
  • Minify HTML (monsterfpc.minifyhtml): When enabled, the engine automatically strips unnecessary whitespace, tabs, and hidden comments from the DOM before saving to disk, keeping files extremely lightweight.
  • Site Sitemaps (monsterfpc.sitemaps): A comma-separated list of your XML sitemaps (e.g., /sitemap.xml). Used by the Dashboard Widget to silently crawl and warm up your cache in the background.

Hole Punching (Dynamic Content)

If you need dynamic content (like a shopping cart, CSRF tokens, or a user greeting) on a fully cached page, you can punch a hole through the static cache using the included Ajax snippet.

Usage Example:

Your snippet:

[[!YourDynamicSnippet? &property1=`value`]]

Must look like this:

[[!MonsterFPC_Ajax? &snippet=`YourDynamicSnippet` &property1=`value`]]

This renders a placeholder and uses the modern asynchronous JavaScript Fetch API to inject the snippet's output natively, without holding up the DOM or breaking the static illusion.

For Developers (The Techy Stuff)

MonsterFPC 2.0 operates mainly on the OnHandleRequest and OnWebPagePrerender events. When an anonymous user requests a URL, the plugin reads a JSON map associated with the current MODX Context to locate the exact resource ID file (e.g., web/15.html).

Because it intercepts the request at OnHandleRequest, it completely skips the MODX database and routing overhead, serving the physical file instantly.

Smart Exclusions & Bot Protection:
  • Disk Exhaustion Shield: The engine strictly refuses to cache your designated 404 (Error) or 403 (Unauthorized) pages. This prevents malicious scripts or "stupid bots" from scanning random, non-existent URLs and filling your server's disk with useless error page caches.
  • URL Normalization: By default, the plugin ignores tracking query strings (like ?fbclid=, ?gclid=, or UTM parameters). This prevents ad-trackers from tricking the cache engine into creating thousands of duplicate HTML files for the exact same page.
  • Native Flags: If a resource has the native MODX "Cacheable" checkbox unchecked, MonsterFPC respects this and bypasses the static generation entirely.
Session Note: The cache only functions for users who are NOT logged in. If you are in the Manager or have an active Frontend session, the cache engine is bypassed so you can work and see your changes in real-time.

Cache Warmer Widget

Version 2.0 includes a dedicated Dashboard Widget to warm up your cache silently.

Simply add the "MonsterFPC Crawler" to your MODX Dashboard. With a single click, it reads your configured XML sitemaps and extracts all the URLs to build a processing queue.

How the Crawler protects your server:

Instead of hitting your server with hundreds of concurrent requests (which would spike your CPU, crash PHP, or trigger your hosting's rate limits), the crawler uses a controlled background iframe mechanism.

  • Throttled Time Lapses: The widget loads one URL at a time into the hidden iframe, waits for a specific time interval (lapse), and only then moves to the next URL. This controlled delay ensures your server has ample time to compile and write the static HTML file before having to handle the next request.
  • Safe Parameter: The crawler appends a special internal parameter (?mfpc_warm=1) to the requests, ensuring the cache engine knows it's an authorized internal process and can process the page cleanly.

MonsterFPC 2.0 Architectural Summary

  • 1. Initialization

    Verifies the existence of MODX and reads the global monsterfpc.enabled setting.

  • 2. Helpers ($isExcluded)

    An isolated anonymous function that processes the monsterfpc.exclude setting. It supports both line breaks and commas to prevent code duplication.

  • 3. OnHandleRequest Event (Read)
    • Filters non-GET methods and the mgr context.
    • Validates GET parameters (only allows q and mfpc_warm).
    • Performs a strict double session check (mgr at the server level and the current context).
    • Runs the $isExcluded() check.
    • Normalizes the URI (uses explode instead of strtok to avoid breaking global MODX routing).
    • Searches the JSON map, verifies the physical file is not empty (filesize > 0), injects the proper HTML headers, and serves it instantly.
  • 4. OnWebPagePrerender Event (Write)
    • Repeats the security filters (GET params, session checks, context limits).
    • Checks the native MODX cacheable flag and completely excludes pages configured as 404/403.
    • Runs the $isExcluded() check.
    • Processes HTML compression using 4 lightweight steps (simple str_replace and preg_replace rules), encapsulated in a temporary variable ($tempOutput) to prevent blank files in case of PHP memory limits.
    • Saves the fully rendered physical file to disk and updates the JSON map.
  • 5. OnDocFormSave Event (Surgical Purging)

    Deletes only the specific physical .html file and the JSON record corresponding to the resource ID that was just saved.

  • 6. OnSiteRefresh Event (Global Flush)

    Deletes the entire physical cache directory and map files when the native MODX cache is manually cleared.

ModX MonsterFPC screenshot
Extra Details
Download / Install Report Issues
Licence

MonsterFPC is free to use for personal and commercial projects.
You may install it on unlimited domains, including local and staging environments.

Redistribution, resale, or rebranding of this package is not permitted.
Please keep attribution to the original author.

The software is provided “as is”, without any warranties or guarantees of fitness for a particular purpose.
Use at your own risk.

If you find MonsterSearch useful, consider supporting its continued development.
I have many ideas for new MODX tools and apps — your support helps me keep creating and improving tools for everyone.

If you would like to support the continued development of this project, consider making a donation.

Support development
Need help?

Questions regarding file permissions or exclusions? Feel free to contact me at any time.

Contact Me