Drakim Posted March 7, 2008 Share Posted March 7, 2008 So, although I'm no beginner when it comes to coding PHP, I've not done much in terms of optimizing. Figuring out that I probably should learn within this area too, I started thinking of ways to optimize my site, mainly to check how much of a difference I can make. So, the first thing I implemented was a caching script. It's pretty simple for the moment being, it saves the output of the current .php file into a .cache file the first time somebody visits the page. Later on, the next time somebody visits, it includes the .cache file content instead of going to the PHP code with all those loops and SQL commands. (of course, the .cache file has an expire date). However, I do not know how this will work with the browser's caching system. How can I ensure that the browser doesn't download the server's cache file every time you visit, but still make sure that I can make it download the cache file anew if it has been changed? Is there some header I can send to tell the browser this? Secondly, I was looking at compression, and figure that this could work very well with the cache system. However, all the compression help I found was about compression on the fly, it seems. Since I have my PHP output ready in the .cache file, can I make it compress it in advance? Also, if the .cache file is compressed in advance, will there be any problem that it isn't served to the client directly, but is included via the original .php file instead? Sorry if some parts was hard to understand, I'll explain better if you ask. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
puritania Posted March 7, 2008 Share Posted March 7, 2008 browsers are looking for a new version of the content by default, if there isn't set any expiring date. if they weren't modified, the server says HTTP/1.1 304 Not Modified. this request takes time, because they'll be executed after parsing the whole html stuff, cause they need to find all the images, css and stuff. So if you have a lot of images in your layout and they don't change recently, you can try the following .htaccess: ExpiresActive On <FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$"> ExpiresDefault A2592000 Header append Cache-Control "public" </FilesMatch> this makes the following: it saves all these files in your browser cache for 1 week (expiresdefault) and loads them before the browser makes a server request to check if they were modified or not. this can really speed up a site. You can compress your css and js scripts by removing all the whitespaces and stuff. I hope, this could help... PS: Google for Yslow Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.