HTTP 1.1 Caching (ETag / If-None-Match)

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
martin42
Forum Members
Forum Members
Posts: 126
Joined: Sat Aug 20, 2005 11:35 pm

HTTP 1.1 Caching (ETag / If-None-Match)

Post by martin42 »

I notice that CMSMS sends content pages and stylesheets in full on every request, even for HTTP 1.1 clients.  Can't we avoid this to save bandwidth?

1. Client makes first GET request for a particular URL.

2. Server sends extra HTTP  header with the content: an MD5 hash of the HTTP response body...
        ETag: 0xedfc43ac

3. Next client request for the same URL will include HTTP header...
        If-None-Match: 0xedfc43ac

4. After generating the dynamic content as normal, the server compares the new ETag MD5 hash with the client's If-None-Match MD5 hash.
If the two MD5 hashes match, then just send...
        304 Not Modified

Never tried this, but I think it's intended to solve the problem you often have with dynamic content, that you need to work out whether the data has changed since this client last requested it, but not at the expense of more file or database I/O.

Any thoughts?
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: HTTP 1.1 Caching (ETag / If-None-Match)

Post by Ted »

Interesting idea.

I'm not totally sure it's doable, except for maybe stylesheets.  There is really no way to know if certain aspects of a page have changed, particuarly with the output of plugins.

Granted, we could do it to save bandwidth also, but that's not as important these days as saving server resouces.  ;)  If you think it might be, then I could probably write something very quickly into the postrender area to do this.
martin42
Forum Members
Forum Members
Posts: 126
Joined: Sat Aug 20, 2005 11:35 pm

Re: HTTP 1.1 Caching (ETag / If-None-Match)

Post by martin42 »

There is really no way to know if certain aspects of a page have changed,
You don't need to know!  Just let the MD5 checksum do the work :-)

Granted, there's a remote possibility of an 'MD5 collision' but with a nice long MD5 hash, that's unlikely. However, you could concatenate two hash functions (say MD5 and SHA) together to make extra certain.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: HTTP 1.1 Caching (ETag / If-None-Match)

Post by Ted »

Oh, I get it.  It's just for bandwidth purposes.  Makes sense.  That would be easily written into index.php and stylesheet.php.  I'll tack it on the list.
martin42
Forum Members
Forum Members
Posts: 126
Joined: Sat Aug 20, 2005 11:35 pm

Re: HTTP 1.1 Caching (ETag / If-None-Match)

Post by martin42 »

Excellent!  I think it will make CMS websites feel a little snappier, especially over dial-up.
Post Reply

Return to “CMSMS Core”