Changeset 603


Ignore:
Timestamp:
May 3, 2017 1:47:56 PM (7 years ago)
Author:
anonymous
Message:

Add application-wide cache control setting 'http_cache_headers'

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/version.txt

    r593 r603  
    1 2.2.0-6
     12.2.0-7
  • trunk/lib/App.inc.php

    r596 r603  
    100100        'signing_method' => 'sha512+base64',
    101101
     102        // Content type of output sent in the Content-type: http header.
     103        'content_type' => 'text/html',
     104
     105        // Allow HTTP caching with max-age setting. Possible values:
     106        //  >= 1    Allow HTTP caching with this value set as the max-age (in seconds, i.e., 3600 = 1 hour).
     107        //  0       Disallow HTTP caching.
     108        //  false   Don't send any cache-related HTTP headers (if you want to control this via server config or custom headers)
     109        // This should be '0' for websites that use authentication or have frequently changing dynamic content.
     110        'http_cache_headers' => 0,
     111
    102112        // Character set for page output. Used in the Content-Type header and the HTML <meta content-type> tag.
    103113        'character_set' => 'utf-8',
     
    476486        if (!$this->cli) {
    477487            if (!headers_sent($h_file, $h_line)) {
    478                 header(sprintf('Content-type: text/html; charset=%s', $this->getParam('character_set')));
     488                header(sprintf('Content-type: %s; charset=%s', $this->getParam('content_type'), $this->getParam('character_set')));
    479489            } else {
    480490                $this->logMsg(sprintf('Unable to set Content-type; headers already sent (output started in %s : %s)', $h_file, $h_line), LOG_DEBUG, __FILE__, __LINE__);
     491            }
     492        }
     493
     494        // Cache control headers.
     495        if (!$this->cli && false !== $this->getParam('http_cache_headers')) {
     496            if (!headers_sent($h_file, $h_line)) {
     497                if ($this->getParam('http_cache_headers') > 0) {
     498                    // Allow HTTP caching, for this many seconds.
     499                    header(sprintf('Cache-Control: no-transform, public, max-age=%d', $this->getParam('http_cache_headers')));
     500                    header('Vary: Accept-Encoding');
     501                } else {
     502                    // Disallow HTTP caching entirely. http://stackoverflow.com/a/2068407
     503                    header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
     504                    header('Pragma: no-cache'); // HTTP 1.0.
     505                    header('Expires: 0'); // Proxies.
     506                }
     507            } else {
     508                $this->logMsg(sprintf('Unable to set Cache-Control; headers already sent (output started in %s : %s)', $h_file, $h_line), LOG_DEBUG, __FILE__, __LINE__);
    481509            }
    482510        }
  • trunk/lib/CSS.inc.php

    r574 r603  
    153153            header('Vary: Accept-Encoding');
    154154        } else {
    155             header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    156             header('Expires: -1');
    157             header('Pragma: no-cache');
     155            // Disallow HTTP caching entirely. http://stackoverflow.com/a/2068407
     156            header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
     157            header('Pragma: no-cache'); // HTTP 1.0.
     158            header('Expires: 0'); // Proxies.
    158159        }
    159160    }
  • trunk/lib/JS.inc.php

    r589 r603  
    153153            header('Vary: Accept-Encoding');
    154154        } else {
    155             header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    156             header('Expires: -1');
    157             header('Pragma: no-cache');
     155            // Disallow HTTP caching entirely. http://stackoverflow.com/a/2068407
     156            header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
     157            header('Pragma: no-cache'); // HTTP 1.0.
     158            header('Expires: 0'); // Proxies.
    158159        }
    159 
    160160    }
    161161
Note: See TracChangeset for help on using the changeset viewer.