We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27376
    • 576 Posts
    I wrote a stupid-simple plugin which compresses the entire output of a page:

    $modx->resource->_output =
        preg_replace('/>\s+</ms', '><', 
        str_replace("\n", '',
        $modx->resource->_output));


    I set this to run at "OnWebPagePrerender" and it works fine, however, this "minified" output isn't what's being cached.

    Is there an event that let's me manipulate $modx->resource->_output before it gets cached so that I'm not compressing the output on every page load?

    #StillWrappingMyHeadAroundRevolution
      • 3749
      • 24,544 Posts
      This might do it: OnBeforeSaveWebPageCache


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 27376
        • 576 Posts
        Hi BobRay, that doesn't seem to do it, the cache still shows the _content with the newlines and further, it doesn't send the minified output to the browser because that event fires during shutdown (after content has been sent to the browser).

        However, thanks for pointing that particular event out as I'm still exploring these two areas. By my guess so far, it should be saving to the cache but it isn't sad. [ed. note: sirlancelot last edited this post 12 years, 2 months ago.]
          • 3749
          • 24,544 Posts
          I'm not sure there's a way to do it then. The only thing I can think of is a plugin that minifies things in OnDocFormSave and un-minifies them in OnDocFormPrerender.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting