Solved

leverage browser caching

Posted on 2013-01-21
11
814 Views
Last Modified: 2013-01-23
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" />
0
Comment
Question by:Braveheartli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38804363
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 38804397
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 38804399
Should I only use the cache code only the pages that I update frequently?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38806283
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
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 38806602
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 38811219
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38811261
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 38811302
No i haven't tried it because i don't know how to check if it's working or not.
Thank u
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 38811308
Redirection works but i dont know how to check image cache
0
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 38811349
thank you
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38811450
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question