Optimizing huuuge site

Status
Not open for further replies.

emp

New member
Jun 29, 2006
7,465
211
0
OK... last 8 months were spent managing the relaunch (technical, design and content) of a huuuuge site.

Now we need to optimize the performance.

I used Yslow and it recommends setting the expire header for some files into the future.

Now, while I understand the concept, I am a bit stumped as to how to add this header to files such as images or CSS.

Err.. apache? Where? How?

Can anyone enlighten me?

Thanks.

::emp::
 


Setup the HTTP header to "Expires: <Date>", where the date is something absurd like year 9999. Be sure to encode the Image names so that if you do need to update the image, you can easily change an image from SomeCompanyLogo01 to SomeCompanyLogo02 (which will force a re-download since it's not the same image being requested).

There are several ways you can do this obviously.

Edit:

Sorry I'm a complete dumb ass, you got that part, simply route your images through a cachable.php file and send the HTTP response header back along with the requested image.
 
Last edited:
OK.. as I said, the concept is clear.
(But thank you for needlessly regurgitating it again anyway)

Now... to the doing?

Thank you.

::emp::
 
Create a php file cachable.php
Code:
<?php 

// output response header 
header("Content-Type: image/gif");
header("Expires: Sun, 1 Jan 9999 01:00:00 GMT");


//output file
readfile ("somefuckingimage.gif");
exit;
?>
And in your HTML, img source is cachable.php, you can obviously change that up to return any image, not just one.
 
Don't change the source in the HTML to cachable.php, use mod_rewrite to redirect the requests on the server to cachable.php so the URL to the browser is still somefuckingimage.gif.

.htaccess said:
RewriteEngine On
RewriteRule (.*)\.gif /cachable.php?file=$1.gif [L]

Or the more direct route, you can set up the expires headers at the web server level with mod_expires:
Apache module mod_expires

If it's a static site though, client-side caching shouldn't really be an issue, a budget dedicated server can handle a hundred requests a second or more to static files easy. If there are dynamic parts, then it's going to be the database or disk IO that become the bottleneck fairly quickly. At that point it's server-side caching you need to be doing (generating static snapshots of the dynamic pages to serve, caching objects/data in memory with memcached, etc).
 
Status
Not open for further replies.