Principle of ahjesus front-end cache reprinted, ahjesus front-end
LAMP cache Diagram
We can see that the website cache is mainly divided into five parts:
Server cache: mainly static servers nginx and squid Based on web reverse proxy, mod_proxy and mod_cache mode of apache2
Browser cache: Includes page html cache and image js, css, and other resource cache.
PHP cache: There are many free PHP buffer acceleration tools, such as apc eaccerlertor.
Memory Cache: mainly uses the distributed cache mechanism such as memcache.
Database cache: You can configure the database cache, data storage process, and connection pool technology.
The following describes the principle of browser caching:
From: we can know that the browser cache is divided into two parts:
The cache of html images, css, js, flash, and other pages is based on saving the page information to the user's local computer hard disk.
The server cache is based on saving the pages accessed by users to the hard disk on the server.
Principle of page Cache
The cache status of the page is determined by the http header. One is the browser request information and the other is the server response information. It mainly includes Pragma: no-cache, Cache-Control, Expires, Last-Modified, and If-Modified-Since. Pragma: no-cache is defined by HTTP/1.0, and Cache-Control is set by HTTP/1.1.
We can see that the principle is divided into three steps:
First request: the browser sends a request to the server through the http header with Expires, Cache-Control, Last-Modified/Etag. At this time, the server records the Last-Modified/Etag of the first request for another request:
When the browser requests again, Expires, Cache-Control, If-Modified-Since/Etag are included in the request to the server.
The server compares the Last-Modified/Etag recorded for the first time with the If-Modified-Since/Etag requested for the second time to determine whether an update is required and then responds to the request.
Parameter description:
The Cache-Control: private/public Public response is cached and shared among multiple users. Private responses can only be used as Private caches and cannot be shared between users.
Cache-Control: no-cache: no Cache
Cache-Control: max-age = x: the Cache time is in seconds.
Cache-Control: must-revalidate: If the page expires, it is obtained from the server.
Expires: Set the page expiration time displayed
Last-Modified: The Last modification time of the request object is used to determine whether the cache expires. It is usually generated by the time information of the files on the server.
If-Modified-Since: The information contained in the request sent by the client means that the Last modification date of the browser cache request object is used to compare with the Last-Modified of the server.
Etag: ETag is a token that can be associated with Web resources. It is not used with Last-Modified and is also an identifier. It is generally used with Last-Modified, improve the accuracy of server judgment.
Reprinted from http://www.vicenteforever.com/2012/05/web-front-cache/
What front-end cache technology does wen have?
Wen? Web
Generally, the distributed cache technology is cached in the memory.
Static websites are also a kind of cache, Which is cached on physical disks.
How can I add front-end JS CSS files and browser cache?
By default, cache is available. What functions do you want to implement?