Commonly used status code classification
The 1xx server received the request. The
2xx request was successful, such as 200
3xx redirection, such as 302
4xx client error, such as 404
5xx server error, such as 500
200 successful
301 permanent redirect (with location, the browser automatically handles it)
means that the browser will remember that URL. 301 will not access it next time,
302 temporary redirect (with location, the browser automatically handles)
302 is a temporary ,
304 Resource not modified
404 Resource not found
403 No permission
500 Server error
504 Gateway timeout
Current methods
get get data
post new data
patch/put update data
delete delete data
Restful API
A new API design method
Traditional API design: treat each URL as a function
Restful API design: treat each URL as a unique resource
Do not use url parameters
Traditional API design: /api/list? id=2
Restful API design: /api/list/2
http cache
Why use caching?
It is necessary to cache the webpages that are not repeatedly accessed, and it is not necessary to reload.
Why use cache?
Because of the network, instability aggravates the instability of loading.
Which resources can be cached?
Business data of static resources (js scc img) cannot be cached
http headers request header
Common Request Headers
Common Response Headers
HTTP request parameter transfer example
Accept the data format that the
browser can receive Accept-Enconding The compression algorithm that the browser can receive, such as gzip browser can parse the compressed package
Accept-Languange browser can receive language, such as zh-Ch
Connection: keep-alive a TCP connection repeat Use the
User-Agent (UA for short) browser information
Content-type format to send data, such as aaplication/json
Custom header
{"X-Requested-With':"XMLHTTPREquest"}
When the front-end accesses the
server, add it before the server returns
Cache related headers
Cache-Control Expores
Last-Modified If-Modified-Since
Etag If-None-Match
Mandatory request
Cache-control
will force the cache once you request it once, and the next time the cache will be directly requested locally, which is faster than network requests and speeds up the rendering speed.
Attributes:
max-age: time cache time can be set
no-cache: no mandatory Cache
no-store does not need to be forced to cache, it is handed over to the back-end for processing
private; maintain the cache
pubilic
http cache-negotiation cache
Server caching strategy The
server judges whether the client resource is the same as the server resource and
returns 304 if it is consistent, otherwise it returns 200 and the latest resource
Three refresh operations
The normal is to directly click the mouse to refresh or go back to the page.
The second type is F5 and the
third type is forced refresh ctrl+F5.
Normal operation: both mandatory cache and negotiation cache are valid
Manual operation: mandatory cache invalidation, negotiation cache is valid
Mandatory refresh: cache invalidation, negotiation cache invalidation