I have found that caching templates has greatly improved performance. But how can I further improve performance by having EE include cache headers to prevent the browser making the same requests time after time?

Ideally I would like to explicitly mark the templates where this is acceptable.

2 Answers 2


I don't think there are any add-ons available currently modify the headers for caching. There is, however, HTTP Header, by Rob Sanchez that you could use as a basis to do this.

It wouldn't be very difficult to modify HTTP Header to include additional header options, or you could turn on PHP for your templates and place the code directly in the templates, but I'd suggest the plugin route.

The CodeIgniter output class has a built-in method for setting headers, which can be accessed from a plugin like this:

$this->output->set_header("Cache-Control: somevalue");
$this->output->set_header("Expires: somevalue");
  • 3
    On reflection this didn't seem to set the response headers at all. Not sure how I missed that the first time. It seems that ExpressionEngine overrides these settings when it finalizes the rendered output. It seems that the only way to avoid this is with the following (but perhaps at some risk): pastebin.com/U7dCKgf1
    – Lea Hayes
    Dec 15, 2012 at 0:06
  • Interesting, since the method I gave you was pulled directly from the HTTP Header plugin. Dec 16, 2012 at 17:02
  • 1
    The HTTP Header plugin is fine with all other headers except the cache ones because one of the EE files overrides the cache headers with a past date (in 1997) right before the rendered content is finalised. It seems that the only way to disable this built-in functionality is to switch off the configuration which may or may not disable other headers from being submitted.
    – Lea Hayes
    Dec 16, 2012 at 17:09
  • Lea, can you go into more detail about what problems might be encountered with all EE headers being disabled? I have a need to turn off the suppression of caching and my search lead me here.
    – Ian Pitts
    Jan 7, 2013 at 16:34
  • UPDATE: I just tested this locally with your pastebin code snippet and it works beautifully for some mega menu templates I'm using on a current site. Additionally, EE still seems to send the cookie set headers.
    – Ian Pitts
    Jan 7, 2013 at 16:40

My general advice would be to forego EE's native caching and turn to something a little more powerful like CE Cache: http://devot-ee.com/add-ons/ce-cache which gives you a host of options as far as caching is concerned, including static page caching. It's one of those add-ons where once you used it, you wonder how you got along before :)

  • 2
    Actually, I don't believe this question is about native caching, but instead adding cache headers to the HTTP request so the browser doesn't refresh the file from the server. Dec 11, 2012 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.