经过大量搜索,阅读我发现的每一个教程并在这里提出一些问题后,我终于设法回答了if-none-match和if-modified-自HTTP请求以来的错误(至少我认为).
要快速回顾一下,这就是我在每个可缓存页面上所做的事情:
session_cache_limiter('public'); //Cache on clients and proxies
session_cache_expire(180); //3 hours
header('Content-Type: ' . $documentMimeType . '; charset=' . $charset);
header('ETag: "' . $eTag . '"'); //$eTag is a MD5 of $currentLanguage + $lastModified
if ($isXML)
header('Vary: Accept'); //$documentMimeType can be either application/xhtml+xml or text/html for XHTML (based on $_SERVER['HTTP_ACCEPT'])
header('Last-Modified: ' . $lastModified);
header('Content-Language: ' . $currentLanguage);
Run Code Online (Sandbox Code Playgroud)
此外,每个页面都有自己的URL(适用于所有语言).例如,"index.php"将在英文URL"/ en/home"和法语"/ fr/accueil"下提供.
我的一个大问题是回答"304 Not Modified"到if-none-match和if-modified-since,因为HTTP请求只在需要时.
我发现的最好的文档是:http: //rithiur.anthd.com/tutorials/conditionalget.php
这就是我所做的实现(这段代码在可以缓存的页面上称为ASAP):
$ifNoneMatch = array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER) ? $_SERVER['HTTP_IF_NONE_MATCH'] : …Run Code Online (Sandbox Code Playgroud)