如何" 304未修改"作品? [英] How "304 Not Modified" works?

查看:162
本文介绍了如何" 304未修改"作品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 如何304未修改产生?

  • How "304 Not Modified" is generated?

如何做一个浏览器判断是否为响应HTTP请求
是304?

How does a browser determine whether the response to a http request is 304.?

这是由浏览器设置或从服务器发送?

Is it set by the browser or sent from the server?

如果服务器发送的,如何知道服务器缓存中提供的数据,也
它是如何设置304到图像?

If sent by server, how does server know the data available in cache, also how does it set 304 to an image?

我猜想,如果浏览器产生的

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());

我靠第三方API提供商获取数据,分析和放大器;它推到数据库。
 该数据可能会或可能不会每次请求时发生变化,但总是头发送 200 ,我不想来解析,检查最后唯一ID在DB&放大器;等..以确定数据的变化,也没有结果比较直接,而我的MD5() SHA1()&安培; CRC32()散列结果和放大器;工作正常,但不知道该算法来确定 304

I am relying on 3rd party API provider to get data, parse & push it to DB. The data may or may not change during every request, but the header always sends 200, I do not want to parse, check the last Unique ID in DB & so on.. to determine the change in data, nor compare the result directly rather I md5(), sha1() & crc32() HASHed the result & works fine, but wondering the algorithm to determine 304

我想用同一种算法来确定数据的变化。

I want to use same kind of algorithm to determine the change in data.

推荐答案

这不是在所有它是如何工作的。

That's not at all how it works.

在浏览器将一些东西在它的缓存,它也存储在该的Last-Modified 的ETag 头服务器。

When the browser puts something in its cache, it also stores the Last-Modified or ETag header from the server.

浏览器然后将与的If-Modified-Since的如果无 - 匹配头的请求,告诉服务器发送304如果内容仍然有日期或ETag的。

The browser then sends a request with the If-Modified-Since or If-None-Match header, telling the server to send a 304 if the content still has that date or ETag.

服务器需要计算日期修改或ETag的每个资源的每个版本的一些方法;这通常来自于文件系统或者一个单独的数据库列。

The server needs some way of calculating a date-modified or ETag for each version of each resource; this typically comes from the filesystem or a separate database column.

这篇关于如何" 304未修改"作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆