MODX Mythbusting: Output Modifiers slow down your site

I have seen this said a couple times and was wondering if this is still true?

I often use this sort of pattern to show/hide buttons dynamically:

[[*btn-link:notempty=`<a class="btn" href="[[*btn-link]]">[[*btn-text]]</a>`]]

Would this really be faster if I made it into a snippet?

[[btn?
    &link=`[[*btn-link]]`
    &text=`[[*btn-text]]`
    &tpl=`<a class="btn" href="[[+link]]">[[+text]]</a>`
]]
$sp = $scriptProperties;
$link = $modx->getOption('link', $sp);
$text =$modx->getOption('text', $sp);
if (empty($link)) return ' ';

return // parse &tpl as a chunk with the link and text placeholders

I don’t think there will be much difference. (The output modifier could even be faster in this case in my opinion). Also, once the page is cached, there is no difference at all.

If you really want to know if it makes any difference, you could use a timing tag, to output the execution/parse time. My guess is, that you won’t see any noticeable difference.


I wouldn’t worry too much about optimising your code, if your page load is generally fast.
And if you feel that your site is too slow, there are usually other areas that you should focus on, that are more effective.

I wouldn’t worry too much about optimising your code, if your page load is generally fast.
And if you feel that your site is too slow, there are usually other areas that you should focus on, that are more effective.

I am definitely in the same camp when it comes to performance, but pagespeed was complaining about the first request taking too long. I was thinking that could be from MODX taking a while to compile the page.

I added the timing tags but realized I don’t have a concept of what is a good time and what is a bad time. it is nice to be able to see wether the page is being compiled just now or if it came from the cache

It’s difficult to say in general, how the parsing time could be improved, as every MODX page is quite unique.

Try first to indentify what part/snippet takes up the most time to run. (A snippet like executioner can help you with that.)


  • Make sure that everything that can be cached, is indeed cached.

  • Maybe a snippet that is slow can be replaced with a faster one. (E.g. pdoResources might be faster than getResources. A custom snippet might be even faster.)

  • Maybe MODX tags can be replaced with Fenom, which might make the parsing faster (in some circumstances).

  • Avoid tags like this [[*field:is=`0`:then=`[[Snippet01]]`:else=`[[Snippet02]]`]] because always both snippets are executed.

1 Like

Avoid tags like this [[*field:is=`0`:then=`[[Snippet01]]`:else=`[[Snippet02]]`]] because always both snippets are executed.

This could be fixed by something like this, right?

[[[[*field:is=`0`:then=`Snippet01`:else=`Snippet02`]]]]

Or a snippet that took a snippet name instead of the snippet results:

[[eitherOr?
  &value=`[[*field]`
  &is=`0`
  &then=`Snippet01`
  &else=`Snippet02`
]]
<?php
if (
  $modx->getOption('value', $scriptProperties) == 
  $modx->getOption('is', $scriptProperties)
) {
    $modx->runSnippet($modx->getOption('then', $scriptProperties));
} else {
    $modx->runSnippet($modx->getOption('else', $scriptProperties));
}
1 Like

See this famous post from MODX core coder Jason Coward (Opengeek).

That said, the post was written in 2012. Servers are a lot faster than they were then, so the speed differences are much smaller.

On the other hand, small page-load-time differences can sometimes make a difference in whether a visitor to your site stays or leaves. I will always use a custom snippet instead of a conditional output modifier, but I like writing PHP code more than I like constructing output modifiers. :wink:

1 Like

I had read that post a while back and was curious if it was still relevant. It sounds like it is, but the speed improvement I can expect from it is not as major as it used to be.