ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Expire and Caching-Values in HTTP-Header

January 12, 2012 10:22am

Subscribe [3]
  • #1 / Jan 12, 2012 10:22am

    olympiaverlag

    1 posts

    We are setting up a website on a few webserver which are based behind two squid-servers (1x loadbalancer / 1x accelerator) to deliver the sites with an optimized performance. So the squid server are handling the traffic, and only when the EE-generated site is expiring the EE-webserver have to deliver a new site to loadbalancer and accelerator.

    Therefore we expected that the Template-Caching-Configuration (http://ellislab.com/expressionengine/user-guide/general/caching.html) defines the Expire- / Last Modified or any Cache-Header-Information of the EE-Sites…

    Until now we couldn’t get that working… The only Expire-Header which is generated is “Expires=Mon, 26 Jul 1997 05:00:00 GMT”. The “Last-Modified”-Header is always up to date - never the less if something has changed on the entry or not. With that information there is no information for an accelerator (and also browser) regarding the caching of a site.

    So how can you configure a valid HTTP-Header based on a relevant Caching-Time?

    Hope you can help us on that topic ...

  • #2 / Jan 13, 2012 6:01pm

    Dan Decker

    7338 posts

    Hi olympiaverlag,

    Welcome to ExpressionEngine and the Forums! We are happy to have you here!

    While your use of loadbalancers and accelerators is outside the scope of support, your question raises some valid concerns. I’ve brought this up to our developers for clarification.

    Thanks!

  • #3 / Feb 15, 2012 1:15am

    JT Thompson

    745 posts

    These are hard coded (sadly) into the EE core files. Normally we do not advocate editing EE core files, however, there is no “hook” for an addon to use to change this value. Until the EE developers provide a method to change this you can do this yourself by commenting out 2 lines in the /system/expressionengine/core/EE_Output.php file, here are the details:

    Line 82 reads:
    $this->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    
    Line 84 reads:
    $this->set_header("Pragma: no-cache");

    comment out both lines with a ‘#’ at the begining of the lines and your Apache expire settings will take over to give you the desired results.

    Make sure you make note of this “hack” as you will have to perform it each time you upgrade EE.

    Cheers!

  • #4 / Feb 16, 2012 2:46pm

    JT Thompson

    745 posts

    To All,

    Just a note on this, if you do make this modification to the EE core file you will need to ensure that the backend part of EE does NOT have Expire headers (this is why the EE software engineers hardcoded this in EE).

    Here is how we do it:

    1. Move your “admin.php” (or whatever you’ve re-named it - which you should do fyi) into a directory under the root of your website (/somedir/admin.php), you’ll need to do this because the Apache directive that controls Expires header information can not be set on a Location context, we will use the Directory context (alternatively you can use .htaccess, however there are performance penalties using .htaccess so we turn that off).

    2. In your apache config (inside the VirtualHost for your website normally) add this for the directory you moved the admin.php to:

    <Directory /full-path/to-website/root/somedir>
        ExpiresActive Off
    </Directory>

    3. Make sure you change the location of your control panel and system folder inside the admin.php AND system/expressionengine/config/config.php files (only the $config[‘cp_url’] setting is needed for the config.php file). Here is an example:

    admin.php:
    $system_path = '../../system'; //because I have it located OUTSIDE the root
    $assign_to_config['cp_url'] = '//mywebsite/somedir/admin.php'; // the double slashes are used to pick up both http and https
    
    config.php:
    $config['cp_url'] = 'somedir/admin.php'; //we actually set this to a dummy file - because admins will know the correct path and name

    4. If you allow users to use EE backend stuff on the frontend (like user profile, Safecracker…) and some EE Addons you will have to verify that they will function correctly with Expires Headers turned on.

    5. This is some fairly technical “stuff” that will require some good knowledge and understanding of Expire Headers and how they work, especially their gotcha’s, I don’t recommend this for the average user.

    There is more (isn’t there always? 😉 ), but this should be enough for those with the technical skill to get started.

    Hope this helps :coolsmile:

  • #5 / Feb 16, 2012 5:41pm

    Dan Decker

    7338 posts

    Hey JT,

    Thanks for the rundown and the caveats, which I will echo.

    Changing anything in the ExpressionEngine Core isn’t recommended or supported.

    The nature of this thread has shifted, so I’m going to move this into Community Help so the info can be amended and updated as other solutions become available.

    Cheers!

  • #6 / Sep 05, 2013 11:21am

    Trendesign

    1 posts

    My apologies for the bump, but I’m really hoping that this can be re-addressed. There has to be a more efficient way to solve this thing. I mean, I can’t be the only one to think that just hard-coding these headers is a viable solution?

    Our IT-guys are asking questions about this, and it has been bugging me as a developer for quite a while. Every time we run a performance audit on our website, this is the only high-priority issue that remains…

    Although I’d really rather not hack into EE’s core, this solution is really close to a desirable result. I just want to get the “Last-Modified”-headers set up right. Is there a way that one might retrieve the current page’s last-edited-time?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases