by Alexander Vassbotn Røyne
16:32:52 Thursday, April 03 2008
How can you speed up your site on an Apache PHP server? Piece of cake if you ask me. How simple is it? With some copy and paste jobs from my article you can speed up your site significally.
Follow these simple and easy steps to make your site faster today!
Always give the browser an opportunity to download gzip (compressed) versions of the content. To do this, here's an example that I did with my javascript files: (As a bonus, we're setting an expires header on the js files aswell!)
Put this code in a .htaccess file in your javascript directory ( I assume you have one, if not, just put it in the folder that you have your .js files in):
Then, make the gzip-js.php file in the /gzip/ directory you're making to do this, and paste this php code in it: (assuming you have a php server)
<?php
header("Content-type: text/javascript; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
There you've done it! Next step: set an expires header to the rest of your content.
A first-time visitor to your page will make several HTTP requests to download all your sites files, but using the Expires header you make those files cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers should be used on all components including scripts, stylesheets, and Flash components.
Put these lines of code in your root .htaccess file.
172800 == 48 hours if my math is correct.
Or put this in your httpd.conf file (preferable).
Remember these .htaccess tips are for apache servers only, and you may want to install mod_header and mod_expires on your web server.
I will continue to update this page, so stay tuned!
Digg,
Kudos, Share on Facebook, Slashdot It!
click here to post a comment