Applies to Joomla 5.4 and 6.x · PHP 8.3 · site builders and extension developers Updated 16 Oct 2026

Most Joomla speed guides start with hosting and end with "install a CDN". On the slow Joomla sites we are asked to fix, the server is rarely the problem. The time goes into the request itself: too many queries, modules that query in a loop, a page cache that is off or wrongly scoped, plugins that run on every request, and a hero image the browser is told to load last.

This is the order in which we profile a slow Joomla 5 or 6 site, with the tools Joomla already ships and the code fixes we apply most often.

1. Measure the request, not the PageSpeed score

A PageSpeed score mixes server time, front-end weight and third-party scripts into one number. Split it first. Time to first byte (TTFB) tells you how long Joomla takes to build the page:

# terminal
curl -o /dev/null -s -w 'TTFB %{time_starttransfer}s  total %{time_total}s\n' https://example.com/blog
# logged in: copy the session cookie from your browser's dev tools
curl -o /dev/null -s -w 'TTFB %{time_starttransfer}s  total %{time_total}s\n' -b "$COOKIE" https://example.com/blog

Run it several times, as a guest and with a session. A guest page that comes from the page cache should answer in well under 200 ms. If it doesn't, the cache isn't serving it. If guest pages are fast but logged-in pages are slow, the problem is in the code and the cache was only hiding it.

Then turn on Debug System (System → Global Configuration → System) on a staging copy, never on the live site. The debug console at the bottom of each page shows three things worth reading:

  • Profile information. The time marks afterInitialise, afterRoute, afterDispatch and afterRender. A big jump before afterDispatch points at the component. A big jump before afterRender points at modules and the template, because modules render in that phase.
  • Database queries. The count, the time per query and the duplicates panel. Fifty queries is normal for a Joomla page. Two hundred, or the same query repeated thirty times, is a module or plugin doing work in a loop.
  • Memory peak. A page that needs 60 MB or more usually loads a large data set it then throws away.

2. The database: where most Joomla time goes

Queries in a loop (N+1)

The most common pattern we remove from custom modules and template overrides is one query per item: load ten articles, then run a query for each one to get its custom field, author or image. The debug panel shows it as the same query with a different ID, ten or a hundred times. Before:

// modules/mod_featured_team/src/Helper/TeamHelper.php
foreach ($items as $item) {
    $query = $db->createQuery()
        ->select($db->quoteName('value'))
        ->from($db->quoteName('#__fields_values'))
        ->where($db->quoteName('field_id') . ' = :field')
        ->where($db->quoteName('item_id') . ' = :item')
        ->bind(':field', $fieldId, ParameterType::INTEGER)
        ->bind(':item', $item->id);   // one query per article

    $item->role = $db->setQuery($query)->loadResult();
}

After: one query for all items, then a lookup in PHP.

// modules/mod_featured_team/src/Helper/TeamHelper.php
$ids = array_map(fn ($item) => (string) $item->id, $items);

$query = $db->createQuery()
    ->select($db->quoteName(['item_id', 'value']))
    ->from($db->quoteName('#__fields_values'))
    ->where($db->quoteName('field_id') . ' = :field')
    ->whereIn($db->quoteName('item_id'), $ids, ParameterType::STRING)
    ->bind(':field', $fieldId, ParameterType::INTEGER);

$roles = $db->setQuery($query)->loadAssocList('item_id', 'value');

foreach ($items as $item) {
    $item->role = $roles[$item->id] ?? '';
}

#__fields_values.item_id is a string column (it holds IDs from any context), so the IDs are bound as strings. Binding them as integers makes MySQL convert every row and skip the index.

Missing indexes in extension tables

Core tables are indexed well. Tables of custom and older third-party extensions often are not. Copy a slow query from the debug panel and run EXPLAIN on it:

# terminal
mysql -e "EXPLAIN SELECT * FROM jos_mycomp_bookings WHERE event_id = 42 AND state = 1 ORDER BY created DESC\G" mydb

type: ALL with a rows estimate close to the table size means a full table scan on every request. The fix belongs in the extension's update SQL, so it ships with the next version instead of living only on one server:

-- administrator/components/com_mycomp/sql/updates/mysql/2.4.0.sql
ALTER TABLE `#__mycomp_bookings` ADD INDEX `idx_event_state_created` (`event_id`, `state`, `created`);

Tables that only grow

Some core tables grow until they slow down every request that touches them. We check these on every audit:

TableWhy it growsWhat to do
#__sessionDatabase session handler; one row per visitor, bots includedKeep the session lifetime short, or switch the handler to Redis or the filesystem on busy sites
#__action_logsUser Actions Log records every admin actionAdd the scheduled task "Delete Action Logs" with "Days to delete action logs after"
#__redirect_linksThe Redirect plugin's "Collect URLs" stores every 404, including bot probesTurn "Collect URLs" off once the redirects are done; empty the table
#__finder_*Smart Search index of every content type that has a finder pluginDisable finder plugins for content you don't search; purge and re-index
#__historyContent versions, unlimited when "Maximum Versions" is highLower "Maximum Versions" in the Articles options
# terminal – the largest tables first
mysql -e "SELECT table_name, ROUND((data_length + index_length) / 1024 / 1024) AS mb, table_rows
          FROM information_schema.tables WHERE table_schema = 'mydb'
          ORDER BY (data_length + index_length) DESC LIMIT 15;"

3. Caching: what Joomla actually caches

Joomla has three cache layers, and they are often confused:

  1. System Cache in Global Configuration. It switches on caching for modules and for components that support it. Conservative caches each module separately, according to its own cache_mode. Progressive caches module output per visitor state and fills the cache folder much faster. We use Conservative.
  2. The module "Caching" option. It only works when System Cache is on, and it caches the module's HTML, not its data.
  3. System – Page Cache plugin. It stores the whole HTML of a page for guests and skips the component, the modules and the template on the next hit. This is the layer that takes TTFB from hundreds of milliseconds down to tens, and the one that breaks things if you don't scope it.

What breaks under the page cache

Anything personal or tied to a session is frozen into the cached HTML and served to the next visitor:

  • Form tokens. A cached login or cart form carries the first visitor's CSRF token, and everyone after them gets "Invalid token". VirtueMart 4.8.0 hit exactly this with cached product modules, see add to cart fails with cached product modules.
  • "Hello, Anna" and cart counters rendered on the server.
  • Pages that vary by cookie, such as currency, language without a URL prefix, or consent state.

Exclude those menu items in the plugin's settings, or render the personal part in the browser and load it with a small AJAX request (com_ajax works well for this). The rest of the page stays cacheable.

Caching data in your own extension

The module cache stores HTML. When the expensive part is the data, for example an API call or a heavy aggregate query, cache the data with a callback controller and keep the rendering live:

// modules/mod_release_watch/src/Helper/ReleaseHelper.php
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Factory;

public function getReleases(string $repo): array
{
    $cache = Factory::getContainer()
        ->get(CacheControllerFactoryInterface::class)
        ->createCacheController('callback', [
            'defaultgroup' => 'mod_release_watch',
            'lifetime'     => 60,      // minutes
            'caching'      => true,    // cache even when System Cache is off
        ]);

    return $cache->get([$this, 'fetchReleases'], [$repo], md5('releases:' . $repo));
}

The third argument is the cache ID. Build it from everything the result depends on, or two different calls will share one entry.

4. Plugins that run on every request

A system plugin's onAfterInitialise or onAfterRoute runs on every request: front end, back end, AJAX and API. Two things we look for in custom and third-party plugins:

  • Work without a guard. The plugin loads settings, queries the database or calls an API before it checks whether it is needed on this page.
  • Legacy listeners. The plugin still relies on method-name matching instead of SubscriberInterface. It works on Joomla 5 and 6 with the compatibility layer, but it can't declare which events it needs. See Joomla 6 plugin events explained.
// plugins/system/myplugin/src/Extension/MyPlugin.php
public static function getSubscribedEvents(): array
{
    return ['onAfterRoute' => 'onAfterRoute'];
}

public function onAfterRoute(AfterRouteEvent $event): void
{
    $app = $this->getApplication();

    // cheapest checks first – leave before touching the database
    if (!$app->isClient('site') || $app->getInput()->getCmd('option') !== 'com_content') {
        return;
    }

    // … the real work
}

The same applies to scheduled tasks. With the Lazy Scheduler on (Scheduled Tasks → Options), due tasks run inside a visitor's request, and that visitor waits for an index rebuild or a mail queue. On any site with real traffic, turn it off and run the scheduler from cron:

# /etc/cron.d/joomla-scheduler
*/5 * * * * www-data /usr/bin/php /var/www/example.com/cli/joomla.php scheduler:run --all >/dev/null 2>&1

5. Front end: the Web Asset Manager and the LCP image

Load assets through the Web Asset Manager

Hand-written <script> tags in a template or override can't be deduplicated, deferred or reordered. Registered assets can. Joomla resolves the dependencies, prints each file once, and you control defer per asset:

// templates/yourtemplate/html/com_content/article/default.php
$wa = $this->document->getWebAssetManager();
$wa->registerAndUseScript(
    'tpl.yourtemplate.code-blocks',
    'media/templates/site/yourtemplate/js/code-blocks.js',
    ['version' => 'auto'],
    ['defer' => true]
);

While you're in there, check whether anything still loads jQuery. Joomla's own front end hasn't needed it since Joomla 4. When it appears, an old extension or override asked for it, and that one call adds about 30 KB of render-blocking script to every page.

Don't lazy-load the image that matters

Joomla's image layout (joomla.html.image) adds loading="lazy" to every image whose width and height it knows. That includes the article's full-text image, which is usually the largest element in the first screen, the Largest Contentful Paint (LCP). A lazy LCP image starts downloading late, and LCP suffers. We override the layout for that one image:

// templates/yourtemplate/html/layouts/joomla/content/full_image.php
$layoutAttr = [
    'src'           => $images->image_fulltext,
    'alt'           => empty($images->image_fulltext_alt) && empty($images->image_fulltext_alt_empty) ? false : $images->image_fulltext_alt,
    'class'         => $imageClass,
    'loading'       => 'eager',   // the layout only adds "lazy" when loading is empty
    'fetchpriority' => 'high',
];

Do the same for the first one or two cards of a blog list. Leave every image below the fold lazy. If an optimization plugin adds lazy loading on its own, check that it respects fetchpriority="high". Ours had to be told to.

6. PHP settings that matter for Joomla

Joomla 5 with a typical set of extensions loads several thousand PHP files. The default OPcache limits are too small for that, so files fall out of the cache and are compiled again:

; /etc/php/8.3/fpm/conf.d/99-joomla.ini
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=50000   ; default 10000
opcache.validate_timestamps=1
opcache.revalidate_freq=60            ; 0 on staging, where files change all the time
realpath_cache_size=4096K
realpath_cache_ttl=600

Check the result with opcache_get_status(). If cache_full is true or num_cached_scripts is at the limit, raise the limit. Keep the PHP version of cron (CLI) and of the web server (FPM) the same. A scheduler that runs on an older CLI PHP fails silently.

The checklist we run

CheckWhereHealthy
Guest TTFB, cached pagecurl -w %{time_starttransfer}< 200 ms
Logged-in TTFBsame, with a session cookie< 800 ms
Queries per pageDebug console< 100, no repeated query
Largest tablesinformation_schema.tablessessions, logs and 404 log under control
Page cache scopeSystem – Page Cacheon, with form and cart pages excluded
Lazy SchedulerScheduled Tasks → Optionsoff, with cron running scheduler:run
LCP imagepage sourceno loading="lazy", fetchpriority="high"
jQuery on the front endpage sourceonly if something really needs it
OPcacheopcache_get_status()not full, file limit above the file count

Fix in that order. The database and cache items usually remove most of the server time. The front-end items fix what PageSpeed reports. A faster server only helps once the request itself is lean.