Mobile app version of vmapp.org
Login or Join
Angela700

: Caching a changing site I run a website where the static content changes at least 4 times a week and I'm trying to figure out the best header arrangement to use. Currently I have all caching

@Angela700

Posted in: #Cache #CacheControl #Http #HttpHeaders #Performance

I run a website where the static content changes at least 4 times a week and I'm trying to figure out the best header arrangement to use.

Currently I have all caching related headers in use. I have cache-control set to must-revalidate with a super low max-age value (60 seconds max). I also have Etag header set to an encoded value of a timestamp that shows when the website is last updated. the Etag value is only changed when the website content is changed. I also have a last-modified header set to the equivalent value of what max-age is but in proper GMT date format. Here's an example of my headers:

HTTP/1.1 200 OK
Date: Tue, 17 Mar 2015 06:24:14 GMT
Server: Apache
Set-Cookie: PHPSESSID=f7cf7d0171b7a7cba54aaddc90c7eabd; path=/;
Vary: Accept-Encoding
ETag: "d06a8d9a82809e0f35669ce1fb80dca3"
Last-Modified: Tue, 17 Mar 2015 04:34:52 GMT
Cache-control: max-age: 5,must-revalidate
Expires: Tue, 17 Mar 2015 06:25:14 GMT
Connection: keep-alive
Content-Length: 22583
Content-Type: text/html; charset=UTF-8


So I'm curious as to what the best way is to cache a site that changes anywhere between 3x a week (when new content is added) and 5x a day (when website is being repaired). At first I think remove the cache-control line entirely but I don't know how proxies will appreciate that, and my current setup right now is contributing to my score of F at webpagetest.org for caching content.

What would you suggest the best header arrangement I should have or should I leave as-is? Any ideas?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Angela700

2 Comments

Sorted by latest first Latest Oldest Best

 

@Miguel251

Unless you've got a sophisticated caching tier, setting a short cache time is no different from not caching at all. Using caching with PHP sessions and not varying by cookie is probably a very bad idea.

The best solution is to set a really long cache time and change the URL when the content changes. How you do that depends on what access you have to your server and what the server is. Running mod_pagespeed on apsache is a really simple solution - but you should have a caching reverse proxy in front.

10% popularity Vote Up Vote Down


 

@Heady270

When new content is launched, it may not be absolutely critical that users see it right away. In that case you could relax your cache controls and allow your content to be cached for an hour or two and not require that the user re-validates. Actually with "must-revalidate", I don't see any point in not allowing your pages to be cached forever.

Otherwise your cache controls appear to me to be reasonable. Removing all cache control headers would allow your pages to be caches for an unspecified amount of time -- not what you want.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme