HTML5¼¼Êõ

ä¯ÀÀÆ÷»º´æ - ¿ÕÒ»×ù¾É³Ç£¬ÊØÒ»¸ö¾ÉÈË

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-11-29 11:21 ÎÒÒªÆÀÂÛ( )

ä¯ÀÀÆ÷»º´æ ×î½ü¶ñ²¹http»ù´¡£¬¿´µ½»º´æÕ½ڣ¬È»ºóÇ°¶Îʱ¼äÓÖÕýºÃ¶Áµ½Ò»Æª½éÉÜä¯ÀÀÆ÷»º´æµÄÎÄÕ£¬Á½Õß½áºÏ£¬ÊÜÒæ·Ëdz¡£×Ô¼ºÒ²°ë³­°ë×ܽáµÄ¼Ç¼һÏ¡£ ä¯ÀÀÆ÷»º´æ¸ÅÊö ä¯ÀÀÆ÷»º´æ·ÖΪǿ»º´æºÍЭÉÌ»º´æ¡£µ±¿Í»§¶ËÇëÇóij¸ö×ÊԴʱ£¬»ñÈ¡»º´æµÄÁ÷³ÌÈçÏ£º 1¡¢Ïȸù

ä¯ÀÀÆ÷»º´æ

×î½ü¶ñ²¹http»ù´¡£¬¿´µ½»º´æÕ½ڣ¬È»ºóÇ°¶Îʱ¼äÓÖÕýºÃ¶Áµ½Ò»Æª½éÉÜä¯ÀÀÆ÷»º´æµÄÎÄÕ£¬Á½Õß½áºÏ£¬ÊÜÒæ·Ëdz¡£×Ô¼ºÒ²°ë³­°ë×ܽáµÄ¼Ç¼һÏ¡£

ä¯ÀÀÆ÷»º´æ¸ÅÊö

ä¯ÀÀÆ÷»º´æ·ÖΪǿ»º´æºÍЭÉÌ»º´æ¡£µ±¿Í»§¶ËÇëÇóij¸ö×ÊԴʱ£¬»ñÈ¡»º´æµÄÁ÷³ÌÈçÏ£º

1¡¢Ïȸù¾ÝÕâ¸ö×ÊÔ´µÄһЩhttp headerÅжÏËüÊÇ·ñÃüÖÐÇ¿»º´æ£¨ºóÎÄÔÙ½âÊÍʲôÊÇÇ¿»º´æ£©£¬Èç¹ûÃüÖÐ(cache hit)£¬ÔòÖ±½Ó´Ó±¾µØ»ñÈ¡»º´æ×ÊÔ´£¬²»»á·¢ÇëÇóµ½·þÎñÆ÷£»

2¡¢µ±Ç¿»º´æûÓÐÃüÖÐʱ£¬¿Í»§¶Ë»á·¢ËÍÇëÇóµ½·þÎñÆ÷£¬·þÎñÆ÷ͨ¹ýÁíһЩrequest headerÑéÖ¤Õâ¸ö×ÊÔ´ÊÇ·ñÃüÖÐЭÉÌ»º´æ£¨ºóÎÄÔÙ½âÊÍʲôÊÇЭÉÌ»º´æ£©£¬³ÆΪhttpÔÙÑéÖ¤(revalidation)£¬Èç¹ûÃüÖÐ(revalidate hitÔÙÑéÖ¤ÃüÖÐ)£¬·þÎñÆ÷½«ÇëÇ󷵻أ¬µ«²»·µ»Ø×ÊÔ´£¬¶øÊǸæËß¿Í»§¶ËÖ±½Ó´Ó»º´æÖлñÈ¡£¬¿Í»§¶ËÊÕµ½·µ»Øºó¾Í»á´Ó»º´æÖлñÈ¡×ÊÔ´£»

3¡¢Ç¿»º´æºÍЭÉÌ»º´æ¹²Í¬Ö®´¦ÔÚÓÚ£¬Èç¹ûÃüÖлº´æ£¬·þÎñÆ÷¶¼²»»á·µ»Ø×ÊÔ´£»Çø±ðÊÇ£¬Ç¿»º´æ²»¶Ô·¢ËÍÇëÇóµ½·þÎñÆ÷£¬µ«Ð­ÉÌ»º´æ»á¡£

4¡¢µ±Ð­ÉÌ»º´æҲûÃüÖÐʱ£¬·þÎñÆ÷¾Í»á½«×ÊÔ´·¢Ëͻؿͻ§¶Ë¡£

ä¯ÀÀÆ÷»º´æ·ÖÀà Ç¿»º´æ:

Ö±°×µãµÄ·½Ê½ÃèÊöÏ£º¿Í»§¶ËµÚÒ»´ÎÎÊ·þÎñÆ÷Ҫij¸ö×ÊԴʱ£¬·þÎñÆ÷¶ª»¹¸ø¿Í»§¶ËËùÇëÇóµÄÕâ¸ö×ÊԴͬʱ£¬¸æËß¿Í»§¶Ë½«Õâ¸ö×ÊÔ´±£´æÔÚ±¾µØ£¬²¢ÇÒÔÚδÀ´µÄij¸öʱµã֮ǰÈç¹û»¹ÐèÒªÕâ¸ö×ÊÔ´£¬Ö±½Ó´Ó±¾µØ»ñÈ¡¾ÍÐÐÁË£¬²»ÓÃÏò·þÎñÆ÷ÇëÇó¡£ÕâÖÖ·½Ê½»º´æÏÂÀ´µÄ×ÊÔ´³ÆΪǿ»º´æ¡£
Ç¿»º´æÀûÓÃhttpµÄ·µ»ØÍ·²¿µÄÖÐExpires£¨ÊµÌåÊײ¿×ֶΣ©»òÕßCache-Control£¨Í¨ÓÃÊײ¿×ֶΣ©Á½¸ö×Ö¶ÎÀ´¿ØÖƵģ¬ÓÃÀ´±íʾ×ÊÔ´µÄ»º´æʱ¼ä¡£·þÎñÆ÷ͨ¹ýÕâÁ½¸öÊײ¿×ֶθæÖª¿Í»§¶Ë×ÊÔ´µÄ»º´æ¹ýÆÚʱ¼äºÍ»º´æ×î´óÉúÃüÖÜÆÚ¡£¿Í»§¶ËµÃÖª×ÊÔ´µÄ»º´æ¹ýÆÚʱ¼äºÍ×î´óÉúÃüÖÜÆں󣬼´¿É×ÔÐÐÅжÏÊÇ·ñ¿É²»½¨Á¢Óë·þÎñÆ÷µÄÁ´½Ó£¬Ö±½Ó´Óä¯ÀÀÆ÷»º´æÖлñÈ¡×ÊÔ´¡£

ÃüÖÐÇ¿»º´æʱ£¬ä¯ÀÀÆ÷ͬÑù»áÊܵ½status=200µÄresponse£¬chromeÖпÉͨ¹ýsizeÇø·Ö´Ó·þÎñÆ÷·µ»ØµÄ×ÊÔ´»¹ÊÇÇ¿»º´æ»ñµÃµÄ×ÊÔ´¡£

Expires:

¸Ã×Ö¶ÎÊÇhttp1.0ʱµÄ¹æ·¶£¬ÖµÎªÒ»¸ö¾ø¶Ôʱ¼äµÄGMT¸ñʽµÄʱ¼ä×Ö·û´®£¬´ú±í»º´æ×ÊÔ´µÄ¹ýÆÚʱ¼ä£¬ÔÚÕâ¸öʱµã֮ǰ£¬¼´ÃüÖлº´æ¡£Æä¹ý³ÌÈçÏ£º

  • ä¯ÀÀÆ÷µÚÒ»´Î¸ú·þÎñÆ÷ÇëÇóÒ»¸ö×ÊԴʱ£¬·þÎñÆ÷ÔÚ·µ»ØÕâ¸ö×ÊԴʱ£¬ÔÚÏàӦͷ²¿»á¼ÓÉÏExpires£¬Èçͼ£º
  • ȱµã£º·þÎñÆ÷·µ»ØµÄExpiresʱµãÊÇ·þÎñÆ÷ÉϵÄʱ¼ä£¬¿ÉÄÜÓë¿Í»§¶ËÓÐʱ¼ä²î£¬Ê±¼ä²îÌ«´óʱ¿ÉÄÜÔì³É»º´æ»ìÂÒ¡£

    Cache-Control:max-age:

    ¸Ã×Ö¶ÎÊÇhttp1.1µÄ¹æ·¶£¬Ç¿»º´æÀûÓÃÆämax-ageÖµÀ´Åжϻº´æ×ÊÔ´µÄ×î´óÉúÃüÖÜÆÚ£¬ËüµÄÖµµ¥Î»ÎªÃ룬Cache-Control : max-age=3600´ú±í»º´æ×ÊÔ´ÓÐЧʱ¼äΪ1Сʱ£¬¼´´ÓµÚÒ»´Î»ñÈ¡¸Ã×ÊÔ´ÆðһСʱÄÚµÄÇëÇ󶼱»ÈÏΪ¿ÉÃüÖÐÇ¿»º´æ¡£Æä¹ý³ÌÈçÏ£º

  • ä¯ÀÀÆ÷µÚÒ»´Î¸ú·þÎñÆ÷ÇëÇóÒ»¸ö×ÊԴʱ£¬·þÎñÆ÷ÔÚ·µ»ØÕâ¸ö×ÊԴʱ£¬ÔÚÏàӦͷ²¿»á¼ÓÉÏCache-Control:max-age=XXXXXXXX£¬Èçͼ£º
  • Cache-ControlÃèÊöµÄÊÇÏà¶Ôʱ¼ä£¬²ÉÓñ¾µØʱ¼äÀ´¼ÆËã×ÊÔ´µÄÓÐЧÆÚ£¬ËùÒÔÏà±ÈExpires¸ü¿É¿¿¡£
    ÕâÁ½¸öHeader¿ÉÒÔÖ»ÓÃÆäÒ»£¬Ò²¿ÉÒÔÒ»ÆðʹÓá£Ò»ÆðʹÓÃʱÒÔCache-ControlΪ׼¡£

    ЭÉÌ»º´æ

    Ö±°×µãµÄ·½Ê½ÃèÊöÏ£º¿Í»§¶ËµÚÒ»´ÎÎÊ·þÎñÆ÷Ҫij¸ö×ÊԴʱ£¬·þÎñÆ÷¶ª»¹¸ø¿Í»§¶ËËùÇëÇóµÄÕâ¸ö×ÊԴͬʱ£¬½«¸Ã×ÊÔ´µÄһЩÐÅÏ¢£¨ÎļþÕªÒª¡¢»òÕß×îºóÐÞ¸Äʱ¼ä£©Ò²·µ»Ø¸ø¿Í»§¶Ë£¬¸æËß¿Í»§¶Ë½«Õâ¸ö×ÊÔ´»º´æÔÚ±¾µØ¡£µ±¿Í»§¶ËÏÂÒ»´ÎÐèÒªÕâ¸ö×ÊԴʱ£¬½«ÇëÇóÒÔ¼°Ïà¹ØÐÅÏ¢£¨ÎļþÕªÒª¡¢»òÕß×îºóÐÞ¸Äʱ¼ä£©Ò»²¢·¢Ë͸ø·þÎñÆ÷£¬ÓÉ·þÎñÆ÷À´ÅжϿͻ§¶Ë»º´æµÄ×ÊÔ´ÊÇ·ñÐèÒª¸üУºÈç²»ÐèÒª¸üУ¬¾ÍÖ±½Ó¸æËß¿Í»§¶Ë»ñÈ¡±¾µØ»º´æ×ÊÔ´£»ÈçÐèÒª¸üУ¬Ôò½«×îеÄ×ÊÔ´Á¬Í¬ÏàÓ¦µÄÐÅÏ¢Ò»²¢·µ»Ø¸ø¿Í»§¶Ë¡£

    µ±Ç¿»º´æδÃüÖÐʱ£¬ä¯ÀÀÆ÷¾Í»á·¢ËÍÇëÇóµ½·þÎñÆ÷£¬·þÎñÆ÷»áÑé֤ЭÉÌ»º´æÊÇ·ñÃüÖУ¬Èç¹ûЭÉÌ»º´æÃüÖУ¬ÇëÇ󷵻صÄhttp״̬Ϊ304£¬²¢»áÏÔʾ˵Ã÷Not Modified£¬ä¯ÀÀÆ÷ÊÕµ½¸Ã·µ»Øºó£¬¾Í»á´Ó»º´æÖмÓÔØÁË¡£

    ЭÉÌ»º´æÀûÓÃ[Last-Modified , If-Modified-Since] ºÍ [ETag , If-None-Match]ÕâÁ½¶ÔHeaderÀ´¹ÜÀí¡£

    ETag & If-None-Match

    ÓÐЩÇé¿öϽöÅжÏ×îºóÐÞ¸ÄÈÕÆÚÀ´ÑéÖ¤×ÊÔ´ÊÇ·ñÓиĶ¯ÊDz»¹»µÄ£º

    Ϊ½â¾öÕâЩÎÊÌ⣬httpÔÊÐíÓû§¶Ô×ÊÔ´´òÉϱêÇ©(ETag)À´Çø·ÖÁ½¸öÏàͬ·¾¶»ñÈ¡µÄ×ÊÔ´ÄÚÈÝÊÇ·ñÒ»Ö¡£Í¨³£»á²ÉÓÃMD5µÈÃÜÂëÉ¢Áк¯Êý¶Ô×ÊÔ´±àÂëµÃµ½±êÇ©(Ç¿ÑéÖ¤Æ÷)£»»òÕßͨ¹ý°æ±¾ºÅµÈ·½Ê½£¬ÈçW/¡±v1.0¡±(W/±íʾÈõÑéÖ¤Æ÷)¡£

    ETagΪÏàӦͷ²¿×ֶΣ¬±íʾ×ÊÔ´ÄÚÈݵÄΨһ±êʶ£¬Ëæ·þÎñÆ÷response·µ»Ø£»

    If-None-MatchΪÇëÇóÍ·²¿×ֶΣ¬·þÎñÆ÷ͨ¹ý±È½ÏÇëÇóÍ·²¿µÄIf-None-MatchÓ뵱ǰ×ÊÔ´µÄETagÊÇ·ñÒ»ÖÂÀ´ÅжÏ×ÊÔ´ÊÇ·ñÔÚÁ½´ÎÇëÇóÖ®¼äÓйýÐ޸ģ¬Èç¹ûûÓÐÐ޸ģ¬ÔòÃüÖÐЭÉÌ»º´æ£¬ä¯ÀÀÆ÷´Ó»º´æÖлñÈ¡×ÊÔ´£»Èç¹ûÓйýÐ޸ģ¬Ôò·þÎñÆ÷·µ»Ø×ÊÔ´£¬Í¬Ê±·µ»ØеÄETag¡£Æä¹ý³ÌÈçÏ£º

    ЭÉÌ»º´æ¹ÜÀí

    [Last-Modified , If-Modified-Since]ºÍ[ETag , If-None-Match]Ò»°ãͬʱÆôÓã¬ÕâÊÇΪÁË´¦ÀíLast-Modified²»¿É¿¿µÄÇé¿ö¡£

    ÆäËû×¢ÒâÊÂÏî

    1.·Ö²¼Ê½ÏµÍ³Àï¶ą̀·þÎñÆ÷¼äµÄÎļþµÄLast-Modified±ØÐë±£³ÖÒ»Ö£¬ÒÔÃ⸺Ôؾùºâµ½²»Í¬·þÎñÆ÷µ¼Ö¶ԱȽá¹û²»Ò»Ö£»

    2.·Ö²¼Ê½ÏµÍ³¾¡Á¿¹Ø±ÕµôETag£¨Ã¿Ì¨»úÆ÷Éú³ÉµÄETag¶¼»á²»Ò»Ñù£¬ÌÔ±¦Ò³ÃæÖеľ²Ì¬×ÊÔ´response headersÖж¼Ã»ÓÐETag£©¡£

    posted on

    ¡¡

    1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

    Ïà¹ØÎÄÕÂ
    • H5±¾µØ´æ´¢ - ¿ÕÒ»×ù¾É³Ç£¬ÊØÒ»¸ö¾ÉÈË

      H5±¾µØ´æ´¢ - ¿ÕÒ»×ù¾É³Ç£¬ÊØÒ»¸ö¾ÉÈË

      2017-11-27 10:16

    • ΢ÐÅä¯ÀÀÆ÷×óÉϽǷµ»Ø°´Å¥À¹½Ø - ²¼¶û-

      ΢ÐÅä¯ÀÀÆ÷×óÉϽǷµ»Ø°´Å¥À¹½Ø - ²¼¶û-

      2017-11-21 08:04

    • H5Ö®audio±êÇ©·ÅÒô¼æÈÝËùÓÐä¯ÀÀÆ÷·½·¨ - ¼üÅÌÇ÷É

      H5Ö®audio±êÇ©·ÅÒô¼æÈÝËùÓÐä¯ÀÀÆ÷·½·¨ - ¼üÅÌÇ÷É

      2017-08-18 15:01

    • http»º´æÓëÀëÏß»º´æ - СÁúÅ®ÏÈÉú

      http»º´æÓëÀëÏß»º´æ - СÁúÅ®ÏÈÉú

      2017-07-18 14:05

    ÍøÓѵãÆÀ
    Æ