I was using Google PageSpeed to optimize a website and got a warning telling me to leverage browser caching. On Google’s Optimize Cache page I didn’t see any instructions for how to do this though. After a little searching I found the following .htaccess code on Premium Press.
Apparently, there are certain security considerations that should be kept in mind according Apache SF.
[cc lang=”bash”]
###########HTTP HEADER START###############
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 year (forever?)
ExpiresDefault A29030400
Header append Cache-Control “public”
# Set up caching on media files for 1 week
ExpiresDefault A604800
Header append Cache-Control “public”
# Set up 2 Hour caching on commonly updated files
ExpiresDefault A604800
Header append Cache-Control “proxy-revalidate”
# Force no caching for dynamic files
ExpiresActive Off
Header set Cache-Control “private, no-cache, no-store, proxy-revalidate, no-transform”
Header set Pragma “no-cache”
###########HTTP HEADER END###############
[/cc]
Thank you! It worked perfectly on my website!
You are welcome. Glad I could help.
Thank you! It is worked perfectly! But it is not working with external java script and css links.
Such as
http://affiliates.hostgator.in/banners/hostgator-300×250.gif (expiration not specified)
http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places (30 minutes)
http://pagead2.googlesyndication.com/pagead/osd.js (60 minutes)
http://pagead2.googlesyndication.com/pagead/show_ads.js (60 minutes)
http://www.googletagservices.com/tag/js/gpt.js (60 minutes)
https://translate.googleapis.com/translate_static/css/translateelement.css (60 minutes)
https://translate.googleapis.com/translate_static/js/element/19/element_main.js (60 minutes)
https://translate.googleapis.com/translate_static/js/element/main.js (60 minutes)
Do you have any solutions
Thanks in Advance
Not working for me,
Using google pagespeed is 60/100.