We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4105
    • 6 Posts
    Hi, I’d like to use MODx’s caching mechanism, but in my current setup this isn’t possible, since my pages may be shown using different templates. I switch the page’s template on request time using the - slightly modified - TemplateSwitcher plugin, choosing the template that matches the browser’s capabilities (especially wether JavaScript is used or not: ie. search engines).

    If I turn caching on, this mechanism fails, because after the first page load, only one version gets cached, which breaks the site quite thouroughly if the next user tries to view it in the other version.

    Is there an easy way to make MODx cache a page for each used template, so that the cache would in fact contain multiple versions of the page? If not, would it be possible for me to create a plugin that does this, or is the caching mechanism too low-level to catch with a plugin?

    I’ll happily build the plugin, but only if necessary smiley

    JW
      • 25663 MODX Staff
      • 12,272 Posts
      There’s no current capability in MODx to accomplish what you’re looking for. The Template Switcher plugin also tends to create some interesting challenges as it disables caching completely which defeats your stated goal.

      My suggestion is to not try to feed specific pages to search engines and just build straight forward relevant content. We don’t employ such techniques on our site and last time I checked we had a PR 7. I think if you check into it that you’ll find that feeding specific pages to search engines, especially Google, is a pretty solid recipe for getting banned—not a good situation if your desire is to win at the SEO game.

      You could most likely accomplish what you describe with a plugin ... but I personally wouldn’t chance it. Once you fall into the abyss, it’s a long crawl out.

        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 4105
        • 6 Posts
        Ah, yes, thanks

        well my goal is not specifically to serve special pages for search engines, but special pages for people without (enough) support for JavaScript and HttpRequest. I use Ajax for the normal site, which loads only the actual content (without head, body, and other overhead). This is done with one template. If the user has no support for Ajax, a clicked url will render the other, default template (including head, body and navigation).

        I did this, because I thought it might give a little performance improvement, since there’s less data going over the line. But this is only html, so maybe it’s not that much. I can put some special tag around the actual content and filter that out when getting it using Ajax.

        However, I still think the system should be able to offer this kind of parallel-caching, since it’s not that uncommon to serve the same content in different layout.

        Well, thanks for your answer, and if I decide to dive in after all, I’ll let you know when I’m climbing out again smiley

        Greetings JW
          • 27376
          • 576 Posts
          There’s a couple ways you get around this, though a "good" template would not require browser specific template switching.

          • Split the template header and footer into chunks and then use a snippet (uncached) to display the chunk if there is a direct request for the page, if it’s an AJAX request, don’t display it.
          • Make your AJAX script only return the parsed documentContent. This may or may not be desirable if your template contains a lot of static code not pertinent to the specific document being requested.
          Personally, I’d shoot for option 1. Option 2 didn’t come in to my head until I read your second post about making selectors around the content and then pulling it out using AJAX.

          Enjoy!
            • 4105
            • 6 Posts
            Thanks for the suggestions.

            Option 1: is certainly a possibillity, although I think it makes the overall picture a bit unclear, hiding away template stuff in chunks (like navigation). But it’s an option. I’m going to consider it.

            Option 2: I don’t use a server-side ajax script, other than MODx itself. I just call the url of the page (with an extra parameter, added by client-side javascript) and MODx serves the page, but now using the template that only returns the content (also with some extra data for the client script). Seemed like a clean mechanism to me.

            About "good" templates: I would like to, but do not agree. I suppose you mean that a well-formed xhtml+css solution should work on all browsers. Maybe in a perfect world. And what about other devices, like phones and pda’s? They might need another layout, or less content. I think it would be wise to do that using different templates, instead of cramming all kinds of switching logic into snippets, calling chunks etc.

            Anyway, that’s why I think that caching should be extended to multiple versions per page, where each version is just the result of another template.

            JW
              • 4105
              • 6 Posts
              Hi all,

              just to let you know: I finally built a plugin that can cache multiple versions of the ’same’ page: ParallelPageCache. It’s in the repository: http://modxcms.com/ParallelPageCache-1.0-1612.html.

              You can define in which situations a version should be cached. For instance: I use TemplateSwitcher, so I tell ParallelPageCache to cache a page for each value of $_REQUEST[’template’] that it encounters. It actually works!
                • 22303 MODX Staff
                • 10,725 Posts
                Very creative Brikkelt. Thanks for the contribution.
                smiley