V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
codermagefox

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

  •  
  •   codermagefox ·
    CoderMageFox · Jun 19, 2017 · 2051 views
    This topic created in 3246 days ago, the information mentioned may be changed or developed.

    今天活儿不多,在整理自己有关于 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 replies    2017-06-20 08:16:13 +08:00
    SoloCompany
        1
    SoloCompany  
       Jun 19, 2017 via iPhone
    给你再多也没用,给你 10mb 的 cookie 每次请求的 header 都超过 10m 你受得了?先不说 header 大小有限制
    Lonely
        2
    Lonely  
       Jun 19, 2017
    然后呢?去把各大浏览器和各路作者都批判一番?
    106npo
        3
    106npo  
       Jun 19, 2017 via Android
    小学的最多最少问题
    标准制定“浏览器至少要支持 4MB cookies ”,那么网页最大可用的 cookies 为多少?
    FrankFang128
        4
    FrankFang128  
       Jun 20, 2017
    前端的中文资料是这样的。瞎扯
    FrankFang128
        5
    FrankFang128  
       Jun 20, 2017
    你应该这么理解:
    既然标准说至少 4k,那么浏览器的下限就是 4k,你的网站要兼容所有浏览器,就应该把 4k 当做上限。
    这么看来书上说得也没错。
    FrankFang128
        6
    FrankFang128  
       Jun 20, 2017
    @xmumiffy 写书的人应该把中间的思路挑明比较好。
    popok
        7
    popok  
       Jun 20, 2017 via iPhone
    那就把现在市面上的主流浏览器拉出来测试一下呗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3056 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 132ms · UTC 14:15 · PVG 22:15 · LAX 07:15 · JFK 10:15
    ♥ Do have faith in what you're doing.