Front end http 【 interview review 】


Status code

  • 1XX server received request
  • 2XX request succeeded, such as 200
  • 3xx redirection, such as 301 permanent redirection, 302 temporary redirection, 304 resource unchanged
  • 4xx client error, e.g. 404
  • 5xx server error, such as 500 server error, 504 gateway timeout


  • Get get data
  • Post new data
  • Patch / put update data
  • Delete delete data

http headers

Request headers

  • The data format that the accept browser can receive
  • Compression algorithms that can be received by the accept encoding browser, such as gzip
  • The language that the accept language browser can receive, such as zh CN
  • Connection: keep alive reuse of a TCP connection
  • cookie
  • Host domain name
  • User agent (UA) browser information
  • Content type format of sending data, such as application / JSON

Response Headers

  • Content type format of sending data, such as application / JSON
  • Content length returns the size of the data, in bytes
  • Content encoding the compression algorithm of the returned data, such as gzip
  • Set-cookie

Cache related headers

  • Cache-Control Expires
  • Last-Modified If-Modified-SInce
  • Etag If-None-Match

HTTP cache

Force cache

Front end http 【 interview review 】

  • Cache control concept

    • In response headers
    • Logic to control forced caching
    • For example, cache control: Max age = 3153600 (s)
  • Value of cache control

    • max-age
    • No cache (no forced caching)
    • No store (no cache)
    • private
    • public
  • Expires

    • Control cache expiration
    • Replaced by cache control

Negotiation cache (compare cache)

Front end http 【 interview review 】

  • Server cache policy
  • The server determines whether the client resource is the same as the server resource
  • If consistent, 304 is returned; otherwise, 200 and the latest resource are returned
  • Two resource identifiers

    • The last modified time of the last modified resource
    • Unique identification of Etag resource (a string, similar to fingerprint)
    • Etag will be preferred
    • Last modified can only be accurate to seconds
    • Etag is more accurate if the resource is repeatedly generated and the content remains unchanged

Front end http 【 interview review 】

Three refresh operations

  • Normal operation: enter URL in the address bar, jump link, forward and backward, etc

    • The forced cache is valid, and the negotiation cache is valid
  • Manually refresh, such as F5, click the refresh button

    • The forced cache is invalid and the negotiation cache is valid
  • Forced refresh: Ctrl + F5

    • Forced cache invalidation, negotiation cache invalidation