Reputation: 1702
morning,
I have few questions about caching a website, since I haven't tried caching a site before. First is how to cache a site so it will have a faster loading when clients browse the site. For example I have many images in my css style, how do I cache this? From what I've read before caching in php is done through the 'head' tag and also caching can be done in the .htaccess (glad I'm using htaccess ^_^).
I added this tags in my header
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="expires" content="-1">
<meta http-equiv="pragma" content="no-cache">//or content="cache"???
Also this is what's inside my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Thanks in advance, will frequently visit, I really like to learn how to cache :)..
Upvotes: 0
Views: 906
Reputation: 91762
As images and other media files to not get processed by php, this is more related to the web-server that you are using so you might want to check on serverfault.com or at least change the php tag for the web-server you are using.
To answer your question; I don't know if the syntax in an .htaccess
file would be the same, but in my apache httpd.conf
file I use the following to tell the visitors browser to cache images for 20 weeks (12096000 seconds):
# Set up caching on media files for 20 weeks
<FilesMatch "\.(jpg|png|jpeg|gif)$">
ExpiresDefault A12096000
Header append Cache-Control "public"
</FilesMatch>
Upvotes: 1