Front-end performance optimization III: Cache

 

1.cache-control attributes:

  If there is a script file can be determined for a long time will not change, and that through the browser can cache up this script, do not always request to the server. This will not only save bandwidth and improve performance.

At this time, just you need to set the file returned HTTP Cache-Control header is set to:Cache-Control: max-age=31536000(以秒计量)



2、expires
Expires also avoid setting up the browser and the server sends requests until time expires.

 

 

3, caching negotiation
To inform the server version of the browser for the current file, it sends a label the last time changes

 Negotiation cache validation steps:

  1. Browser: Hey, I need jquery.min.js this document, if it is the last-modified: Tue, modified after 26 Nov 2019 13:25:13 GMT, please send me.

  2. Modified server which checks the file)

  3. Server: Hey, this document has not been modified after that time, you already have the latest version.

  4. Browser: Great, I'll be displayed to the user.

4、ETag
And similar last-modified, but the level is higher than the number of last-modified.
 
  1. Browser: Hey , I need haorooms the main . CSS file, there is no mismatch "61213-1762a-50bf790757204" this string
  2. server which checks the ETag ...)
  3. Server: Hey , here is my version of "61213-1762a-50bf790757204" , you have the latest version
  4. 浏览器:好,那就可以使用本地缓存了
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/150536FBB/p/12367690.html