leverage browser caching

Dear Experts,

I checked my web site on Google PageSpeed Insights and it reccomends that I should leverage browser caching?
How can I leverage browser caching?

I updated my web page weekly and I use below code on my page for my visitors to see the last updates..

<meta http-equiv="cache-control" content="no-cache" />
 
<meta http-equiv="pragma" content="no-cache" />
 
<meta http-equiv="expires" content="0" />
LVL 1
BRMarketingAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
Caching of HTML documents isn't what matters the most so the 'meta' tags aren't that important.  This page http://tutorialpedia.org/tutorials/Apache+enable+file+caching+with+htaccess.html shows how to set cache and expiration times on the server for other types of files like images.  It is not unusual for image files to be much larger than the HTML page they are used in.  If the image does not change very often, it speeds up the page loading to load it from the browser cache but you have to request that on the server because an image file has no 'meta' tags.
0
 
Dave BaldwinFixer of ProblemsCommented:
Actually, that is the opposite of what they are recommending.  "no-cache" is intended to force the browser to get content from the server every time.  To "leverage browser caching", you want the page to be cached as long as possible in the browser so it does not have to be fetched from the server.  PageSpeed looks at the headers returned from the server to see what expiration dates are requested.

If you are on shared hosting, you usually can't change the expiration times except maybe thru 'htaccess' on Apache.  I'm not sure what you would do on IIS.  In any case, to speed up browsing and lower the number of server accesses, you would want to remove those 'meta' statements from your pages.
0
 
BRMarketingAuthor Commented:
Dear DaveBaldwin
I have a dedicated server.
What happens if I remove the codes ?

<meta http-equiv="cache-control" content="no-cache" />
 
<meta http-equiv="pragma" content="no-cache" />
 
<meta http-equiv="expires" content="0" />

can my users see the last updates on my page if I remove the code ?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
BRMarketingAuthor Commented:
Should I only use the cache code only the pages that I update frequently?
0
 
COBOLdinosaurCommented:
In general you need the no cache meta tags for pages that change frequently, or are dynamically generated with changed data.  The only pages you should remove the no cache meta tags on are pages that do not change on a regular basis.

If a browser has a page in cache, it will not even request if from the server, it will just use cache, so you need to have an expiry on it or it could end up in browser cash forever; depending on user settings.

Cd&
0
 
BRMarketingAuthor Commented:
Dear DaveBaldwin

is it correct to write .htaccess file like this

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif)$">
  Header set Cache-Control "max-age=864000, public, must-revalidate"
  Header unset Last-Modified
</FilesMatch>
0
 
Dave BaldwinFixer of ProblemsCommented:
That looks like it should work. http://dense13.com/blog/2008/02/27/redirecting-non-www-to-www-with-htaccess/

Have you tried it yet?
0
 
BRMarketingAuthor Commented:
No i haven't tried it because i don't know how to check if it's working or not.
Thank u
0
 
BRMarketingAuthor Commented:
Redirection works but i dont know how to check image cache
0
 
BRMarketingAuthor Commented:
thank you
0
 
Dave BaldwinFixer of ProblemsCommented:
Did you find a way to check the HTTP headers to make sure your cache expiration is being included?  In Firefox, I use LiveHTTP Headers or Fiddler.  You can also use Wireshark to check the headers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.