如何生成"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 data
// what is that algorithm.?
return result;
}
console.log(is_modified());
Run Code Online (Sandbox Code Playgroud)
我依靠第三方API提供程序来获取数据,解析并将其推送到数据库.在每个请求期间数据可能会也可能不会发生变化,但是标题总是发送200,我不想解析,检查DB中的最后一个唯一ID等等来确定数据的变化,也不直接比较结果而是我md5(),sha1()&crc32()HASHed结果和工作正常,但想知道算法来确定304.
我想使用相同类型的算法来确定数据的变化.