I asked my host if they supports mod_expires or not, they told me that it is supported. I use CakePHP and I tried the following code in webroot/.htaccess
and `app_root/.htaccess but Google's page speed is stile considering there is issue in caching of css, js, png, jpg, etc. it found them 24 hour! as the screenshot shows below
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>
The above code is adopted from this article.
Also I used the following:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 year"
ExpiresByType text/html "access 1 month"
# ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType text/javascript "access 1 year"
ExpiresByType application/javascript "access 1 year"
# ExpiresByType application/x-shockwave-flash "access 1 month"
# ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 year"
</IfModule>
Also I tried to use both codes with each other but the Google Speed tell me the same. Look at the following screen shot:
I need to know how could I solve this issue?!!
Edit##
Using firebug in Firefox I noticed that only resources in the
app/views/themed/slate/webroot
are not be affected with the cache settings regarded above, but those found directly inapp/webroot
, i.e without, theming are affected well.
It seems to be a bug in cakephp. In cakePHP 1.3+ the themed view assets have been moved from
app/webroot/themed/themeTitle
toapp/views/themed/themeTitle/webroot
.According to CakePHP 1.3 documentation you are able to restore the old place (i.e. in the main webroot) of the themed static assets by creating
app/webroot/theme/themeTitle
So, what I have done for solve this issue is to copying all files in
app/views/themed/slate/webroot
toapp/webroot/theme/slate
The following screen shot is from FireFox Firebug that shows an image file get the expire after one year in seconds: