Jump to content

Compression and caching question


Drakim

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.