2.4.3.19. Server does not return Last-Modified HTTP header
Attention!
The header will not be returned for dynamic content if any options of the PageSpeed module are activated.
By default, virtual hosting servers return the HTTP header Last-Modified for static content (images, style sheets, JS scripts). If you encounter a situation where the server does not return this header, you should check whether the "SSI" option is enabled in the site settings:
If the "SSI" option is enabled, the server will not return a header for content delivered by the Apache web server. For static content, the header will be returned in any case. The operation of SSI technology is ensured by the modules of the Apache web server, which we use as a backend server on hosting. The official documentation states that when using SSI, the Last-Modified header is not returned, as it is difficult to calculate the last modification time for dynamic content.
For dynamic content (dynamic pages, PHP scripts), this header must be transmitted independently. The following code can be used as an example:
<?php
$LastModified_unix = 1294844676; // time of last page modification
$LastModified = gmdate("D, d M Y H:i:s \G\M\T", $LastModified_unix);
$IfModifiedSince = false;
if (isset($_ENV['HTTP_IF_MODIFIED_SINCE']))
$IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5));
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
$IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5));
if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) {
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
exit;
}
header('Last-Modified: '. $LastModified);
You can check the operation of the header and get additional recommendations for working with it on the site last-modified.com.