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?

0

3 Answers 3

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"
Sign up to request clarification or add additional context in comments.

3 Comments

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.
@yomoore, this file should be in same folder where index.php file is placed, use Notepad++ or some IDE (netbeans, PhpStorm), don't use Notepad (he adds invisible stupid symbols in start of file).
It works now:) I downloaded notepad++ and copyd your text. And I also removed the php...Thanks a lot, you saved my day.
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

1 Comment

How is this any different from what I already have? It looks to me its the same.
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".

2 Comments

What do you mean by ''Your server is currently sending "max-age: 0"'' How did you check this?
Get the LiveHttpHeaders plugin for Firefox. Update: Ah now its 6000. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.