Chapter 7. Tutorial: Optimize Your Site Step by Step

Step 7: Page Caching

Until now, your site has built every page from scratch for every visitor, and JCH Optimize has optimized it each time. A page cache stores the finished, optimized page and sends that copy to the next visitors, which can cut the server's response time (TTFB) from a second or more to a few hundredths of a second. It comes last because while you are still changing settings, you want to see your changes immediately.

Procedure 7.8. Switch on the page cache
  1. Make sure no other page caching extension or plugin is active.

  2. Switch the page cache on:

    Joomla

    Open the Mode Switcher in the status bar and click its page cache item. This enables the System - JCH Optimize Page Cache plugin. You can also enable the plugin in System → Manage → Plugins; the page cache item in the dashboard's Notifications panel takes you there.

    WordPress

    On the settings page, Page Cache tab, set Enable to Yes and save.

    Figure 7.18. Switching on the page cache
    The Mode Switcher menu in the Joomla status bar with its page cache item.

    Joomla

    The Page Cache tab of the WordPress Configurations page with the Enable switch.

    WordPress


  3. Open your site in a private window and visit a few pages twice. The second visit should feel almost instant.

  4. Check anything that changes per visitor: a shopping cart, a login form, a "recently viewed" list, a contact form's confirmation message.

Logged-in users never get cached pages, and by default nor does a visitor who has just submitted a form (Exclude form users), so carts and confirmations keep working for them.

Fixing problems
A page shows out-of-date or someone else's content

Exclude it from caching: add part of its address to Exclude urls on the Page Cache tab. On Joomla you can also exclude menu items or whole components.

Your site shows different HTML on phones and computers

Some templates send different pages to phones. Switch on Platform specific so phones and computers get separately cached copies. Most modern templates don't need this.

Going Further: Serving Pages Without PHP Pro

Even with a page cache, your site still starts up for each visit to find the cached copy. Serve Cached Pages as Static Files saves cached pages as plain files that your web server sends directly, without starting your site at all.

  1. On the Page Cache tab, set Serve Cached Pages as Static Files to Yes and save. On Apache, JCH Optimize adds the rules to your .htaccess file automatically, and each saved page is sent with the security headers your site sends with it, such as those of Joomla's HTTP Headers plugin. On Nginx, add the JCH Optimize include to your server configuration, or ask your host to. Nginx sends the saved pages without those headers, so set them in the include as well: the comments in the file show how.

  2. Test your pages again as a visitor, and test anything that changes per visitor.

Caution

Because your site doesn't start for cached visits, anything that must run on every visit (a visitor counter, some cookie consent or geolocation extensions) won't. If something stops working, switch this setting off; the normal page cache still does most of the work.