Unless I'm mistaken, Drupal is changing the "Last-Modified" HTTP header for a page any time the page cache is regenerated - even if the raw content remains identical. This means that clients end up having to re-download exactly the same information any time the page cache is regenerated even for pages that have not changed at all.

I realize that I can improve this situation by trying to engineer things such that the page caches are not regenerated unless the resource has changed, but is there any way I can set things up such that the Last-Modified header genuinely reflects whether or not the content has changed? This would seem to me to be a more robust solution.

  • I should add - I have a similar issue with Etags. I would like to use them to identify whether or not the resource has changed, but it seems that Drupal treats these completely differently to how I would like too.
    – Pryo
    Mar 25 '15 at 12:13

The code that is causing the issues you're describing lives in drupal_serve_page_from_cache(). Instead of using a hash of the contents of the cache; Drupal uses the $cache->created value. Looking over everything hacking core is the only option at the moment. I'll see if there can be a way of not hacking core if one has total control of the cache backend; if there is a way look for an update inside of https://www.drupal.org/project/apdqc


You can add headers which will be delivered for newly rendered as well as responses retrieved from the page cache from within hook_boot. However, it might end up being rather challenging to determine the true modification date of any resource at this point in the request/response cycle (think of changes in other regions than the main content, e.g. blocks, panel panes, ...).

Also keep in mind that Last-Modified and ETag headers are only useful for bandwith optimization. This is extremely important for large static assets (images, CSS, JavaScript) but its generally not worth the hassle when delivering markup.

While I do not recommend it, you actually can override those headers from within a hook_boot() implementation in a custom module.

 * Implements hook_boot()
function MYMODULE_boot() {
  drupal_add_http_header('Last-Modified', 'Thu, 1 Jan 1970 00:00:00 GMT');
  drupal_add_http_header('ETag', 'abcdefg');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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