compare_modified_date
The compare_modified_date function allows you compare the modified on date for the page with the "If-Modified-Since" header in the request to see if a "304 Not Modified" http status code should be returned. If the "If-Modified-Since" date sent from the browser in the request is the same as the "last modified" date of the page then a 304 http status code is automatically set, no content is returned and the response is sent.
{% do compare_modified_date() %}
This is often used with the header function in a template to set the page to be cached in the browser.
{# Tell the browser to cache something for 30 days #}
{% set expiry = now|date_modify('+30 days') %}
{% do header('Cache-Control: max-age=' ~ (expiry.timestamp - now.timestamp)) %}
{% do header('Pragma: cache') %}
{% do header('Expires: ' ~ expiry|date('D, d M Y H:i:s', 'GMT') ~ ' GMT') %}
{# NORMAL HTML TO GET/DISPLAY CONTENT #}
{# At the end of the template compare the modified date. Need to wait until the end so that the modified date is retrieved from the content for the page #}
{% do compare_modified_date() %}
Arguments
The compare_modified_date function has the following signature.
compare_modified_date()