Web浏览器是否以不同方式缓存HTML文件和PHP生成的文件?

I'm using Nginx as web server and Firefox to view response headers. For testing, I had two files on the server with the same content: test.html and test.php. In the Nginx configuration file, the expires directive is set to 30d in the server context.

When accessing test.html in a web browser multiple times, the browser first obtains a 304 Not Modified response and serves a copy cached in the browser. However, when accessing test.php, the browser always makes a full request to the server (200 OK) without using the browser cache.

The questions are:

  1. Is the behaviour (i.e. different treatment of HTML and PHP generated files) normal?
  2. What could be done to make web browsers cache HTML and PHP generated files in the same way?

nginx sets the response header for the static file, included in the headers are:

  • Cache-Control
  • Expires
  • Last-Modified

Cache-Control tells the client (at least) how to cache the content.

Expires and Last-Modified allow the client to determine when to fetch new content.

What you must do is ensure that PHP sends the same headers, or sensible headers if not exactly the same; Now that you know which headers are important, inspecting the requests in your browser will tell you how to achieve this.