Okay, now that I know HTTP headers are not the source of my site's slowness, and have a slightly better understanding of how caching works in general in MODX, I'm hoping I can get some help on speeding up my very slow website.
I'll begin with some very brief overview of how my site is set up. Please don't judge too harshly.
My MODX templates basically all look like this:
[[setTemplatePlaceholders?&outputChunk=`html`]]
"setTemplatePlaceholders" is a big, fat master snippet that determines which banner, menus & other custom content to swap in, and basically sets a bunch of placeholders - then returns the chunk 'html' (or whichever chunk you specify).
One of the main things the snippet does is find a "Site Definition Resource" in the current' resource's ancestor hierarchy. This is a resource that uses a particular template, with TVs that basically define a sub-site. Which banner to use, the title of the sub-site, certain layout options, etc. All of the child descendents of such a resource need to display those same "site definition" properties, so the snippet finds the "Site Definition Resource" and sets a bunch of placeholders accordingly.
Each template also has some custom properties; My 'html' chunk calls other chunks like 'css', 'js', 'divStructure', 'innerContentStructure', etc., which can be overridden by properties in the template.
For whatever reason (file under, 'it seemed like a good idea at the time'), over the years I've moved away from having direct calls to things like getResources, Wayfinder, etc. in my chunks, instead moving towards calling all those things from within "setTemplatePlaceholders" and setting placeholders in my chunks. (I guess my thought was, the fewer separate snippet calls, the better. I honestly have no idea whether this is a legit theory, but it is the direction I've gone in.)
So here's the problem. Uncached, this snippet is taking roughly 2.25 to 2.5 seconds to load - even on pages that barely have anything going on content-wise.
I know, I know. All I can say is, given the environment here, page load performance really hasn't come up as an issue until recently. I always figured I'd eventually take a look at the numbers and address the issues I found. And now is that time.
So.
There are several possible issues that I already know I can/should look in to to begin taming this beast and getting my site load time down to acceptable levels. And there are probably more issues I'm not yet aware of, that hopefully some of you can help me out with.
- Is my "run all of the snippets from one master snippet & set placeholders" approach a worse approach than putting the individual snippet calls directly into my template chunks?
- Is my "store all the details about which sub-site a page belongs to in the TVs of some resource in the parent hierarchy, and retrieve them each time" approach an incredibly inefficient/stupid one? I've thought of maybe writing a plugin that saves some of this stuff locally to a resource when it is saved (at least the id of the "site definition resource"). Would that be better?
- Is there a good way to use 'getCache' to cache this snippet, on a per-resource basis, in a custom cache partition so that it doesn't get overwritten every time the site cache gets cleared?
I definitely think #3 (which I just became aware of today) has potential. But if #1 and/or #2 would significantly speed up the processing of this snippet (or the total load time of a page, if I bust-up this snippet), I'd definitely want to do that as well. I've already been experimenting with flattening-out my "chunk hierarchy"; not having so many granular layers of chunk calls built in to my template logic. This seems to be helping a bit - although I haven't done a significant amount of data collection thus far.
Any ideas or thoughts would be highly appreciated. I'm happy to share more about what my code is doing if that might help as well.