Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

leverage browser caching

Posted on 2013-01-21
11
Medium Priority
?
827 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
  • 6
  • 4
11 Comments
 
LVL 84

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
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.

 
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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

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 84

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
Suggested Courses

926 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