1

I'm trying to reduce the HTTP requests. I have a web page with a lot of unique visitors each day, and every visitor enters the page 35 times a day. This page is only a script in JS that once in 24 hours calls another page. So I've been told that if I want to reduce the server's load, I should use HTML cache. The problem is that I don't know what would be the best setting for me, as there is a lot of options "Public","private",etc.. Can anyone help me out with that?

I don't mind that I won't have the option to change the content of the page immediately, I'll have to wait my delay time until the update would be in everyone's cache also.

Eli_Rozen
  • 1,301
  • 4
  • 20
  • 31

2 Answers2

0

You could install Varnish to cache your website. Basically, before requesting a page from your website it'll lookup the page in Varnish and if it's there, it'll return the cached HTML version instead.

If you need to update the contents of your website, you can simply clear the Varnish cache so it'll use your new HTML instead (which will then be cached again).

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
  • Should I really use it? The system is a PHP-based system that logs statistics about users, when each user has it's own data so it won't help me there. The only page that is only-HTML (and JS) is this one page, the others are all PHP. – Eli_Rozen Mar 20 '12 at 19:40
  • It could still work: PHP generates the page and Varnish caches it. As long as the cached version is still the same as the HTML that PHP would generate, you can give the cached version to the user. So if the content only changes every 24 hours then you only need to generate the page once with PHP. For the rest of the day the cached version can be used. – Simeon Visser Mar 20 '12 at 19:51
0

The best way to control caching is to the set proper HTTP headers. Since your comments state that you use PHP, I would recommend you to have a look at PHP's header(), which can be used to set the HTTP-headers for your page.

To cache the page for 24 hours, you could put this at the head of your page:

<?php header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (24 * 60 * 60))); ?>

It can also be done through the .htaccess file if your running an Apache web server. Have a look at this SO post for more info on how to.

For more information about expires-headers, have a look a Yahoo's article about expires headers.

Community
  • 1
  • 1
Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103