PHP cache management doesn't seem to work

Please take a look at my website: vynora

He did not finish. I placed the PHP header at the top of my HTML page:

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
<?php
  header("Cache-Control: max-age=6000");
?>

When I go to pages on Google, it tells me that I have to optimize the browser cache, please look: Google pagespeed

But I already used PHP. So how is this possible?

+3
source share
3 answers

The problem is not this page, not the PHP scripts. See Google recommendations:

The following cached resources have a short freshness life. Indicate at least one week in the future for the following resources:

, .
, Apache. mod_expires

, .htaccess :

ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 86400 seconds"
ExpiresByType application/x-javascript "access plus 86400 seconds"
+2

, :

header("Cache-Control: private, max-age=6000, pre-check=6000");
header("Pragma: private");
header("Expires: " . gmdate("D, d M Y H:i:s"). " GMT");

GZIP:

http://www.whatsmyip.org/http_compression/?url=aHR0cDovL3d3dy52eW5vcmEuY29tLw==

, gzipped

http://redbot.org/?uri=http%3A%2F%2Fwww.vynora.com%2F

, gzipped

+1

This may not work, because there are spaces before the () header. Try this as follows:

<?php 
    if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
        ob_start("ob_gzhandler"); 
    } else {
        ob_start();
    }
    header("Cache-Control: max-age=6000");
?>

You should also set an expired header because older browsers do not understand the “maximum age”.

Btw: Your server is currently sending "max-age: 0".

+1
source

All Articles