Last Modified Header vs Expire Header vs eTag - Avinash Zala - Web Development Expert

Last Modified Header vs Expire Header vs eTag

What is Last Modified Header?

The Last Modifies header field indicate the date and time at which origin server believe your file was last modified.

Last-Modified = “Last-Modified” “:” HTTP-date

For example:
Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT

What is Expire Header?

When any user comes first time at that time your browser will make number of HTTP requsets to download all the contents. With Expire Headers you can make those contents cachable for certain (defined) time, so for next it will load the content from the cache instead of making the request to server content.

Expire header should be applied to all static components including CSS, js, Flash files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    # Set Expire Date to 15 Apr 2011
    Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
    # You can set Fixed time also
    ExpiresActive On
    ExpiresDefault A300      # 5 Min
    ExpiresDefault A2700     # 45 Min
    ExpiresDefault A3600     # 1 Hour
    ExpiresDefault A54000    # 15 Hour
    ExpiresDefault A86400    # 1 Day
    ExpiresDefault A518400   # 6 Days
    ExpiresDefault A604800   # 1 Week
    ExpiresDefault A1814400  # 3 Week
    ExpiresDefault A2419200  # 1 Month
    ExpiresDefault A26611200 # 11 Month
    ExpiresDefault A29030400 # 1 year , Never Expire
    # You can use any of the time limit based on your content refresh time.
</FilesMatch>

Be sure that you should not catch the content for more that one year, as its violets the RFC guidelines for Catching the content in browser.

What is eTag?

Have you ever looked at Browser Response Header? You will see one thing which is eTag, Then What is this eTag?

eTag is the Entity Tags, an Unique identifier associated with the each resource of the site.

To turn of the eTag you can use below code in .htaccess fie.

1
FileETag None

When ever your browser make the request to the any resource, first it will check the eTag and if-match header to check the resource is modified or not since last it was cache.

You can see the Browser Response headers using Firebug Net Panel, Please have a look at the below image for the reference.

Conclusion:

From my point of view you should do below to make the proper caching.

Use the expire header by setting the far expiration date.

If you have used the Expire Header then you should disable the Last Modified Header, This is because, some browsers are blocking the Last Modified Header if Expire Header is available.

If you have used the Expire Header then you should disable the eTag , reason is same as for Last Modified.

Let me know your suggestion by commenting here.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: