As I mentioned in my answer about ETags
, the responsibility to provide the header always lies with the resource provider.
And just as with ETags
, there may be ways that the web server or framework can automate the creation of the header. By far the most common case is that web servers serving static files can use the files' modification time to set the Last-Modified
header.
It's harder to automate with dynamic applications, since there's generally not a standard source of that information. To take an example I'm familiar with, Django allows you to specify a function that will be called to get the Last-Modified
date. It's up to you to put the application-specific logic into that function, but the framework will populate the header and do the comparison to return Not Modified
responses.
My impression is that most dynamic applications don't bother with the Last-Modified
header. If you have to provide custom logic to figure out the caching headers, you might as well just provide the ETag
, which is generally preferred. Also, with ETags
you can often avoid doing any application-specific logic at all if the framework will hash the response for you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…