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
Today I encountered a problem when I used Dockerf...
Table of contents 1. Learn to return different da...
Isolation of process address spaces is a notable ...
I spent a day on it before this. Although Seata i...
This article mainly introduces the analysis of th...
RULES can be used to control the style of the int...
1. Installation version details Server: MariaDB S...
How to get the container startup command The cont...
MySQL version: MySQL Community Edition (GPL) ----...
If you don't have a Linux system, please refe...
Solution: Just set the link's target attribute...
Table of contents 1. Vue installation Method 1: C...
1. First prepare the MySQL and Eclipse environmen...
This article shares the specific code for WeChat ...
This article shares the specific code of js to im...