This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

We've heard the criticism: concrete5 isn't as fast it should be, on low-end hardware. Know that we're taking this to heart with our next version, due out in several months. concrete5 version 4 should feature a number of improvements to speed up both the editing and viewing processes, including more AJAX-based editing (which reduces costly and time-consuming page refreshes) and much more usage of the built-in cache.

However, there are other ways to speed up a concrete5 site that can be done today. Your site can benefit by removing certain unneeded or unused portions of code.

1. Don't use jQuery? Don't load it!

concrete5 uses jQuery extensively, and we love it (at least, I do.) However, it's not necessary for all front-end functions. If you're not using jQuery in your site on every page, remove it from the required header for users who aren't logged in. This will ensure that the site doesn't load unnecesssary and costly JavaScript, while also keeping it editable.

To do this: 

1. Copy concrete/elements/header_required.php into your local elements/ directory.
2. Open this file, and locate these lines:

  1. $this->addHeaderItem($html->css('ccm.base.css'), 'CORE');
  2. $this->addHeaderItem($html->javascript('jquery.js'), 'CORE');
  3. $this->addHeaderItem($html->javascript('ccm.base.js'), 'CORE');

3. Change those lines to this:

  1. if ($u->isRegistered()) {
  2. $this->addHeaderItem($html->css('ccm.base.css'), 'CORE');
  3. $this->addHeaderItem($html->javascript('jquery.js'), 'CORE');
  4. $this->addHeaderItem($html->javascript('ccm.base.js'), 'CORE');
  5. }

2. Don't make your theme editable.

I think the way we've enabled designers to make editable stylesheets is one of concrete5's coolest, nearly-unknown features. (Click here for an introduction and example.) However, if you're working on a site for a client, you probably don't need this. Furthermore, did you know that by enabling this feature, you're parsing a stylesheet for editable rules, when you don't need to?

Granted, the stylesheet gets cached, and you're probably not losing a lot of performance. But every little bit helps, and waste is waste. To change this, look for any lines in your theme that are called this way:

  1. $this->getStylesheet('my_stylesheet.css');

and change them to:

  1. <?=$this->getThemePath()?>/my_stylesheet.css

3. Make sure you're running an opcode cache on your web server.

This is a must. Make sure you're at least running Zend Optimizer on your web server. If at all possible, forego Zend Optimizer entirely, and use something like APC, XCache or eAccelerator. (Note: we used to recommend eAccelerator primarily, but its lack of maintenance concerns me. Perhaps APC instead?)

4. Building Custom Blocks? Don't put expensive logic in their constructor!

We've seen it frequently, and we may even have been guilty of it from time to time. What's that? Putting block startup logic in the block constructor (the __construct) method.

Why is this bad? Isn't that where it's supposed to go? Well, block's get instantiated at several points in concrete5, and that means that the block is going to run those functions every time that happens. Instead, stick your block startup logic in a method named "on_start." That method only runs once (plus, you can be sure it will run at the right point.) 

5. Use API Methods whenever possible.

Rather than making custom calls to concrete5 tables, use the API methods if at all possible. How does this help performance? Well, here's the trick: it doesn't always. Sometimes (*gulp*) it might even hurt performance. 

But - and this is a big but - in the long run, these are the best methods to use for performance and code accuracy. In version 4, we're going to be addressing caching for a large number of built-in objects, including attributes, users and files (pages and their attributes are already cached.) This means that if you use the built-in API for files or users, you'll automatically get caching, and that means performance increases. 

Loading Conversation