3

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?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Youss
  • 4,196
  • 12
  • 55
  • 109

3 Answers3

2

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:

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"
OZ_
  • 12,492
  • 7
  • 50
  • 68
  • Hi, I have been looking for the .htaccess on my server but I can't find it....Could it be that I have delete it by accident?? Is this possible? How do I make a new one. I tried it with notepad and saving it as .htaccess When I place it next to my index.php the webpage doesn't function (error) When I put it in the root (next to public file mail etc) it doesnt do anything. – Youss May 28 '11 at 13:43
  • @yomoore, this file should be in same folder where index.php file is placed, use [Notepad++](http://notepad-plus-plus.org/) or some IDE (netbeans, PhpStorm), don't use Notepad (he adds invisible stupid symbols in start of file). – OZ_ May 28 '11 at 13:47
  • It works now:) I downloaded notepad++ and copyd your text. And I also removed the php...Thanks a lot, you saved my day. – Youss May 28 '11 at 14:09
1

To cache page into users browser add theses headers:

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==

says its gzipped

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

says its gzipped

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
1

This may not work because there is possible whitespace before header(). Try it like this:

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

You should set the expired header as well, because old browsers do not understand "max-age".

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

reeaal
  • 347
  • 3
  • 14