Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please see: <a href="http://www.jonasjohn.de/snippets/php/caching.htm" rel="nofollow">http://www.jonasjohn.de/snippets/php/caching.htm</a>, you have to check the incoming request headers to send the right response. You can do something like below:</p> <pre><code>&lt;?php ob_start(); $filemtimes = array(); foreach(array('file1.js','file2.js') as $file) { include_once($file); $filemtimes[]= filemtime($file); } $date = gmdate('D, d M Y H:i:s', max($filemtimes)).' GMT'; $length = ob_get_length(); $etag = md5($date.$lengte); $headers = apache_request_headers(); if(!empty($headers['If-None-Match']) &amp;&amp; !empty($headers['If-Modified-Since'])) { if ( $etag == md5($headers['If-Modified-Since'].$length) ) { ob_end_clean(); header("Content-type: application/x-javascript"); header('Last-Modified: '.$date."\r\n"); header('Expires: '.gmdate('D, d M Y H:i:s', (time()+3600)).' GMT'."\r\n"); header('Cache-Control: max-age=3600'."\r\n"); header('ETag: '.$headers['If-None-Match']."\r\n"); header('HTTP/1.1 304 Not Modified'); header('Connection: close'); exit; } } header("Content-type: application/x-javascript"); header('Last-Modified: '.$date."\r\n"); header('Expires: '.gmdate('D, d M Y H:i:s', (time()+3600)).' GMT'."\r\n"); header('Cache-Control: max-age=3600'."\r\n"); header('ETag: '.$headers['If-None-Match']."\r\n"); header('Content-Length: '.$length."\r\n"); header('Accept-Ranges: bytes'."\r\n"); ob_end_flush(); exit; ?&gt; </code></pre> <p>Your script will be cached. No data is send to the client. Server side the includes and modification calculation is done for every request. Maybe store etag and modification time in session or cookie to do the check before includes and calculations. Or check filesizes instead of includes.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload