View Full Version : browser caching .htaccess
simonf
10-29-2016, 11:42 AM
Hi Guys & Girls
I'm trying to make browser caching work on a website, I think I followed all the rules with my .htaccess file (below) and report of what tester say below that....
Any idea what I'm doing incorrectly??
Thanks in advance....
.htaccess file content:
__________________________________________________
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
ErrorDocument 404 http://www.silvertreeestates.co.za/404page.html
__________________________________________________
But when testing site, it still says:
"Expiration not specified" for all files.
[MOD EDIT] large repetitive code dump removed
Beverleyh
10-29-2016, 01:04 PM
Looks like a syntax error - try "access plus 1 year" (or whatever).
simonf
10-29-2016, 01:21 PM
HI Beverley
Tried that, still the same.... confusing me like hell....
styxlawyer
10-29-2016, 03:58 PM
This page (http://httpd.apache.org/docs/current/mod/mod_expires.html) implies that the time keywords for .htaccess should be plural (years, months, days etc.), however the comments at the end say that either singular or plural are acceptable. It might be worth trying the plurals.
simonf
10-30-2016, 02:51 PM
HI Styxlawyer... tried that... to no avail, even tried the following which should also work to no avail....
Anymore suggestions people.....
##############################################
# Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "modification plus 1 seconds"
ExpiresByType image/x-icon "modification plus 1 week"
ExpiresByType image/jpeg "modification plus 1 week"
ExpiresByType image/png "modification plus 1 week"
ExpiresByType image/gif "modification plus 1 week"
ExpiresByType application/x-shockwave-flash "modification plus 1 week"
ExpiresByType text/css "modification plus 1 week"
ExpiresByType text/javascript "modification plus 1 week"
ExpiresByType application/javascript "modification plus 1 week"
ExpiresByType application/x-javascript "modification plus 1 week"
ExpiresByType text/html "modification plus 1 week"
ExpiresByType application/xhtml+xml "modification plus 600 seconds"
</ifModule>
# Cache-Control Headers
<ifModule mod_headers.c>
#month
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
#week
<filesMatch "\.(css|js)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
#day
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=43200, private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# Turn ETags Off
<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None
# Remove Last-Modified Header
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
ErrorDocument 404 http://www.silvertreeestates.co.za/404page.html
##############################################
Beverleyh
10-30-2016, 03:20 PM
Note from Mod : Don't forget to format your code using the # button in the toolbar.
Have you checked if mod_expires is enabled on the server? You can do that by taking out the opening and closing <ifModule> tags and changing the syntax back to "access plus 1 year" etc. If the server reports a 500 error, the module might not even be installed so you should ask your web host to enable it.
simonf
11-02-2016, 09:31 AM
HI Beverley
Thanks for the input the other day re being enabled on the server on my ISP, they moved my site to another server and it seems to work now with the following code below.
But I'm still not finished as on smart phones, this does not show as working.... any suggestion you bright lovely people out there :rolleyes:
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "modification plus 1 seconds"
ExpiresByType image/x-icon "modification plus 1 week"
ExpiresByType image/jpeg "modification plus 1 week"
ExpiresByType image/png "modification plus 1 week"
ExpiresByType image/gif "modification plus 1 week"
ExpiresByType application/x-shockwave-flash "modification plus 1 week"
ExpiresByType text/css "modification plus 1 week"
ExpiresByType text/javascript "modification plus 1 week"
ExpiresByType application/javascript "modification plus 1 week"
ExpiresByType application/x-javascript "modification plus 1 week"
ExpiresByType text/html "modification plus 1 week"
ExpiresByType application/xhtml+xml "modification plus 600 seconds"
</ifModule>
# Cache-Control Headers
<ifModule mod_headers.c>
#month
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
#week
<filesMatch "\.(css|js)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
#day
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=43200, private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# Turn ETags Off
<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None
# Remove Last-Modified Header
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
ErrorDocument 404 http://www.silvertreeestates.co.za/404page.html
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.