Solved

leverage browser caching

Posted on 2013-01-21
11
798 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 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now