Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP cache control doesn't seem to work

Please take a look at my website:vynora

It's not finished. I have put a PHP header in 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 pagespeed of Google it tells me that I should optimize my browser cache, please take a look:Google pagespeed

But I already did using PHP. So how is this possible?

like image 604
Youss Avatar asked Dec 27 '25 21:12

Youss


1 Answers

Problem not in this page and not in PHP scripts. See Google's suggestions:

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

  • http://www.vynora.com/arrow.png (expiration not specified)
  • http://www.vynora.com/bing.png (expiration not specified)
  • http://www.vynora.com/dailymotion.png (expiration not specified)
  • http://www.vynora.com/dd_arrow.gif (expiration not specified)
  • http://www.vynora.com/deviantart.png (expiration not specified)
  • http://www.vynora.com/flickr.png (expiration not specified)
  • http://www.vynora.com/google.png (expiration not specified)
  • ...

It means, you should cache your static files.
As I can see, you use Apache. In this case you can use mod_expires

For example, you can add into .htaccess file this lines:

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"

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!