V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
codermagefox
V2EX  ›  前端开发

看书中一个关于 Cookie 标准的问题,求助。

  •  
  •   codermagefox ·
    CoderMageFox · 2017-06-19 21:26:34 +08:00 · 1523 次点击
    这是一个创建于 2492 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天活儿不多,在整理自己有关于 Cookie 的知识。 对于 Cookie 的缺陷,MDN 是这样写的: 3.Cookie 的大小限制在 4KB 左右。对于复杂的存储需求来说是不够用的。

    然后发现《 JavaScript 权威指南》 20.2.4 对于 Cookie 的局限性是这样描写的: Cookie 的局限性 然后我一时兴起就去找了一下所谓的[RFC2965]( https://www.ietf.org/rfc/rfc2965.txt ) 原文是这样的:

    5.3 Implementation Limits

    Practical user agent implementations have limits on the number and size of cookies that they can store. In general, user agents' cookie support should have no fixed limits. They should strive to store as many frequently-used cookies as possible. Furthermore, general-use user agents SHOULD provide each of the following minimum capabilities individually, although not necessarily simultaneously:

      *  at least 300 cookies
    
      *  at least 4096 bytes per cookie (as measured by the characters
         that comprise the cookie non-terminal in the syntax description
         of the Set-Cookie2 header, and as received in the Set-Cookie2
         header)
    
      *  at least 20 cookies per unique host or domain name
    

    我瞬间懵逼了啊!!人家不明明说的是 at least 300 cookies 么!不是明明就是 at least 4096 bytes 么!按照我的理解,也就是说,标准根本就没有做限制,现在的限制标准只是浏览器自己加的吧!

    感觉自己瞬间卡住了,没法总结了,求 V2 的老司机指点一下,是我理解错了吗,还是书上扯淡了?

    7 条回复    2017-06-20 08:16:13 +08:00
    SoloCompany
        1
    SoloCompany  
       2017-06-19 23:27:30 +08:00 via iPhone
    给你再多也没用,给你 10mb 的 cookie 每次请求的 header 都超过 10m 你受得了?先不说 header 大小有限制
    Lonely
        2
    Lonely  
       2017-06-19 23:38:06 +08:00
    然后呢?去把各大浏览器和各路作者都批判一番?
    xmumiffy
        3
    xmumiffy  
       2017-06-19 23:40:08 +08:00 via Android
    小学的最多最少问题
    标准制定“浏览器至少要支持 4MB cookies ”,那么网页最大可用的 cookies 为多少?
    FrankFang128
        4
    FrankFang128  
       2017-06-20 00:49:26 +08:00
    前端的中文资料是这样的。瞎扯
    FrankFang128
        5
    FrankFang128  
       2017-06-20 00:52:18 +08:00
    你应该这么理解:
    既然标准说至少 4k,那么浏览器的下限就是 4k,你的网站要兼容所有浏览器,就应该把 4k 当做上限。
    这么看来书上说得也没错。
    FrankFang128
        6
    FrankFang128  
       2017-06-20 00:55:27 +08:00
    @xmumiffy 写书的人应该把中间的思路挑明比较好。
    popok
        7
    popok  
       2017-06-20 08:16:13 +08:00 via iPhone
    那就把现在市面上的主流浏览器拉出来测试一下呗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 10:02 · PVG 18:02 · LAX 03:02 · JFK 06:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.