Web Development

Expire Header | Cache-Control Header | Best Practice to Speed up your website

For rich interface websites for first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable.

There are two aspects to this rule:

  • For static components: implement “Never expire” policy by setting far future Expires header
  • For dynamic components: use an appropriate Cache-Control header to help the browser with conditional requests

For rich interface websites for first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on all components including scripts, stylesheets, and Flash components.

Browsers user cache to reduce the number and size of the HTTP requests and making the page loads faster. A we server uses expire header in HTTP request to tell the client ( Browser ) how long a component can be cached.
[cc lang=”php”]
Expires: Thu, 15 Apr 2010 20:00:00 GMT
[/cc]
Above line will tell browser to cache the component in the HTTP request to until 15 April 2010.
If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request.
[cc lang=”php”]
ExpiresDefault “access plus 10 years”
[/cc]
This trick works only if user have already visited your site once. This has no effect in performance if the user if visiting your website for first time using empty cache.

By using a far future Expires header, you increase the number of components that are cached by the browser and re-used on subsequent page views without sending a single byte over the user’s Internet connection.

Source : Yahoo Tips

Shares:
  • […] Contact « Expire Header | Cache-Control Header | Best Practice to Speed up your website […]

    Reply
  • student
    student
    September 22, 2010 at 5:31 am

    Valuable info. Lucky me I found your site by accident, I bookmarked it.

    Reply
  • Fausto Zerkle
    Fausto Zerkle
    September 22, 2010 at 9:01 am

    I really appreciate what you write about here. I try and check your blog every day so keep up the good work!

    Reply
  • Howard Guelpa
    September 23, 2010 at 8:17 pm

    this really is def. 1 of the greater subject matter

    Reply
  • Karen Allard
    September 24, 2010 at 2:30 pm

    I would like to stay in touch, What is your facebook page?

    Reply
  • Woddy
    September 25, 2010 at 9:33 am

    Nice post and this fill someone in on helped me alot in my college assignement. Thank you on your information.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *