S
S
sadieff2017-02-07 11:40:10
MODX
sadieff, 2017-02-07 11:40:10

How to pass Last-Modified headers to modx?

Good day, developers! I want to display the Last-Modified header and 304 code for a site on MODX.
Found the plugin:

<?php
switch ($modx->event->name) {

  case 'OnManagerPageInit':
    $cssFile = MODX_ASSETS_URL.'components/modlastmodified/css/mgr/main.css';
    $modx->regClientCSS($cssFile);
    break;
        
    case 'OnWebPagePrerender':
        $modified = date("r", strtotime($modx->resource->get('editedon')));
        header ("Last-Modified: $modified");

        $modx->resource->_contextKey = $modx->resource->context_key;
        $cache = $modx->cacheManager->getCacheProvider($modx->getOption('cache_resource_key', null, 'resource'));
        $key = $modx->resource->getCacheKey();
        if ($cache->get($key)) {
            $qtime = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : '';
            if (strtotime($qtime) >= strtotime($modified)) {
                header ("HTTP/1.1 304 Not Modified ");
                header("Expires: " . date("r", time() + 3600));
                exit();
            }
        }
        header("Expires: " . date("r", time() + 3600));
        break;
}

As a result, the 304 page code is transmitted, but Last-Modified does not want to. As a result, the last-modified.com/ru check fails here.
Although if you clear the cache, the code 200 is returned on the first load, and "last-modified: Wed, 18 Jan 2017 22:28:27 +0300" comes with it, but it doesn't want to with 304 at all. In which direction to dig?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sadieff, 2017-02-07
@sadieff

It turns out that everything works, just the last-modified.com/ru verification service is not friendly with https. The console and Yandex webmaster say that everything is ok.

Z
zooks, 2017-02-07
@zooks

Disable caching for main. I didn't find any other way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question