Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately you can't easily discern whether or not a client has cached a page from PHP or any server environment. You can, however, advise browsers on whether or not to cache and for how long. This is accomplished by setting the Cache-Control HTTP header (and friends). See <a href="http://palizine.plynt.com/issues/2008Jul/cache-control-attributes/" rel="nofollow">this page</a>. Most folks tend to specify caching for up to a few hours in the future, so users will see stale data for no more than 2 hours. I'd recommend this, but you can also instruct browsers to effectively turn caching off altogether. Anyhow, the simplest solution in my opinion is to set these headers in your .htaccess file.</p> <p>Here's an example with a 2-hour time limit:</p> <pre><code># Cache CSS and JS files for up to 2 hours &lt;FilesMatch "\.(css|js)$"&gt; &lt;IfModule mod_headers.c&gt; # Set Max-age to 7200 seconds (2 hours), revalidate after 2 hours (ask the server if the file's changed) Header set Cache-Control "max-age=7200, must-revalidate" &lt;/IfModule&gt; FileETag MTime Size &lt;/FilesMatch&gt; </code></pre> <p>Another option is to allow caching, but force the client to ask the server if anything has changed on every request. This won't have as large of a benefit, especially on pages serving many css and js files (normally the case with Drupal) as the browser will still have to make a round-trip request to the server for each file:</p> <pre><code># Only use cache if checking with the server results in a 304 (Not Modified) &lt;FilesMatch "\.(css|js)$"&gt; &lt;IfModule mod_headers.c&gt; # Instruct the client and possibly proxies in front of the client to check for new versions every 0 seconds (always) Header set Cache-Control "max-age=0, public, must-revalidate, proxy-revalidate" # For older browsers Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT" &lt;/IfModule&gt; FileETag MTime Size &lt;/FilesMatch&gt; </code></pre> <p>Finally, you can ask the browser to disable caching. I wouldn't recommend this unless you're certain that files will change very frequently, as page load times will suffer:</p> <pre><code># Disable caching &lt;FilesMatch "\.(css|js)$"&gt; &lt;IfModule mod_headers.c&gt; Header set Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0" # For older browsers Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT" &lt;/IfModule&gt; FileETag MTime Size &lt;/FilesMatch&gt; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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