When developing and debugging a web application, you will often encounter the trouble of having to clear the browser cache or force a refresh to test it. Here are some settings for Apache no-cache configuration and nginx no-cache configuration. There are two common cache settings, both of which are set using add_header: Cache-Control and Pragma. nginx: location ~ .*\.(css|js|swf|php|htm|html )$ { add_header Cache-Control no-store;add_header Pragma no-cache; } For static content that is not frequently modified on the site (such as images, JS, and CSS), you can set an expiration time on the server to control browser cache, thereby effectively reducing bandwidth traffic and reducing server pressure. Take Nginx server as an example: location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { #The expiration time is 30 days. #Image files are rarely updated, so you can set a larger value when they expire. #If you update frequently, you can set it smaller. expires 30d; } location ~ .*\.(js|css)$ { expires 10d; } [ Background ]: Expires is a header field in the Web server response message. When responding to an http request, it tells the browser that the browser can directly retrieve data from the browser cache before the expiration time without requesting again. 【 Related information 】 1. Cache-control strategy Cache-Control and Expires have the same function, both of which indicate the validity period of the current resource and control whether the browser directly retrieves data from the browser cache or resends a request to the server to retrieve data. It’s just that Cache-Control has more options and more detailed settings. If set at the same time, its priority is higher than Expires. HTTP protocol header Cache-Control : The value can be public, private, no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, max-age The meanings of the instructions in each message are as follows:
Last-Modified/If-Modified-Since
What it ultimately achieves is equivalent to setting up these three types of HTML caching technologies: <meta http-equiv="pragma" content="no-cache"/> <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/> <meta http-equiv="expires" content="0"/> This is the end of this article about the detailed case of Nginx cache settings. For more relevant Nginx cache settings, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of TIMESTAMPDIFF case in MySQL
Table of contents 1. Variable Overview 1.1 Storag...
p>Manually start in "Services" and i...
Ubuntu 16.04 builds FTP server Install ftp Instal...
This article shares the specific code for JavaScr...
If you want to display extra text as ellipsis in ...
Generally, the colspan attribute of the <td>...
Table of contents 1. Build Docker 2. Enter the co...
Table of contents 1. What is componentization? 2....
1. Avoid declaring the page as XML type . The pag...
Flexible layout (Flexbox) is becoming increasingl...
Preface We all know that the QR codes in official...
In this article, we will look at how to develop a...
Overview Today I will mainly share how to correct...
MySQL foreign key constraint (FOREIGN KEY) is a s...
Table of contents Find and fix table conflicts Up...