“304 Not Modified”响应是如何生成的?
浏览器如何判断对 HTTP 请求的响应是否为 304?
是浏览器设置的还是服务器发送的?
如果由服务器发送,服务器如何知道缓存中可用的数据,以及如何将 304 设置为图像?
我的猜测,如果它是由浏览器生成的:
function is_modified()
{
return get_data_from_cache() === get_data_from_url();
}
function get_data_from_cache()
{
return some_hash_or_xxx_function(cache_data);
}
function get_data_from_url()
{
return some_hash_or_xxx_function(new_data);
}
function some_hash_or_xxx_function(data)
{
// Do something with the data.
// What is that algorithm?
return result;
}
console.log(is_modified());
我依靠第三方 API 提供商来获取数据、解析并将其推送到我的数据库。每次请求期间数据可能会或可能不会更改,但标头始终发送200
. 我不想解析,检查数据库中的最后一个唯一 ID 等等......以确定数据的变化,也不想直接比较结果,而是对结果进行md5()
哈希处理sha1()
并且crc32()
工作正常,但我想知道算法来确定304
。
我想使用同一种算法来确定我的数据的变化。