Do web browsers cache HTML files and PHP generated files differently?


Flux

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

When accessing test.html multiple times in a web browser, the browser first gets 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 (200 OK) to the server without using browser caching.

The issue is:

  1. Is the behavior (i.e. different handling of HTML and PHP generated files) normal?
  2. How can I make web browsers cache HTML and PHP generated files the same way?
Joe Watkins

nginx sets response headers for static files, these headers include:

  • Cache-Control
  • Expires
  • Last-Modified

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

Expiresand Last-Modifiedallow the client to determine when to fetch new content.

What you have to do is make sure that PHP sends the same header, or the incorrect header. Now that you know which headers are important, examining the request in the browser will tell you how to implement this header.

Related


How do browsers cache files and images?

Pars As far as I know, when someone visits a website for the first time, some files and images will be saved next time to load faster. But how do browsers cache images and files? Do browsers only cache local files? For example: Are /images/....files or images

How do browsers cache files and images?

Pars As far as I know, when someone visits a website for the first time, some files and images will be saved next time to load faster. But how do browsers cache images and files? Do browsers only cache local files? For example: Are /images/....files or images

How to cache PHP generated XML files in Joomla?

jock I'm generating an xml file that takes too long to generate, which is a big problem for me because some XML integrations don't work due to the lag time. I want to cache an xml copy of this xml file, but I don't know how to do this, here is the code that ge

How to cache php generated files on CloudFlare?

Rodriff I want to add jpg and pdf files generated by php pages to cloudflare cache with «index.php? file=hola.pdf» URL. The generated files are static and the same every time, but I don't think they're cached because of the php file extension. what can I do? W

How to cache php generated files on CloudFlare?

Rodriff I want to add jpg and pdf files generated by php pages to cloudflare cache with «index.php? file=hola.pdf» URL. The generated files are static and the same every time, but I don't think they're cached because of the php file extension. what can I do? W

How to cache PHP generated XML files in Joomla?

jock I'm generating an xml file that takes too long to generate, which is a big problem for me because some XML integrations don't work due to the lag time. I want to cache an xml copy of this xml file, but I don't know how to do this, here is the code that ge

How to cache php generated files on CloudFlare?

Rodriff I want to add jpg and pdf files generated by php pages to cloudflare cache with «index.php? file=hola.pdf» URL. The generated files are static and the same every time, but I don't think they're cached because of the php file extension. what can I do? W

Using browsers to cache static files

user3767643: I'm not sure, how in Golang we can take advantage of browser caching with only static files (for example CSS) jsand not HTMLtemplate files . With .htaccessApache, it's easy to use, but I don't see any such thinggolang I would like to know, but whe

Using browsers to cache static files

user3767643: I'm not sure, how in Golang we can take advantage of browser caching with only static files (for example CSS) jsand not HTMLtemplate files . With .htaccessApache, it's easy to use, but I don't see any such thinggolang I would like to know, but whe

Using browsers to cache static files

user3767643: I'm not sure, how in Golang we can take advantage of browser caching with only static files (for example CSS) jsand not HTMLtemplate files . With .htaccessApache, it's easy to use, but I don't see any such thinggolang I would like to know, but whe

Using browsers to cache static files

user3767643: I'm not sure, how in Golang we can take advantage of browser caching with only static files (for example CSS) jsand not HTMLtemplate files . With .htaccessApache, it's easy to use, but I don't see any such thinggolang I would like to know, but whe

Using browsers to cache static files

user3767643: I'm not sure, how in Golang we can take advantage of browser caching with only static files (for example CSS) jsand not HTMLtemplate files . With .htaccessApache, it's easy to use, but I don't see any such thinggolang I would like to know, but whe

Exported SVG files are rendered differently in browsers

Taxus I'm having trouble understanding what's causing this file to render differently in browsers (Chrome: axes only visible, Safari and FF show main content and axes). The figure was exported from the DC.js example page (the first figure) using SVG- crowbar2

Exported SVG files are rendered differently in browsers

Taxus I'm having trouble understanding what's causing this file to render differently in browsers (Chrome: axis only visible, Safari and FF showing main content and axis). The figure was exported from the DC.js example page (the first figure) using SVG- crowba

How do web browsers find source maps for JavaScript files?

John Sanderson The following article explains that in order to locate a JavaScript file, such as a source map of jQuery , the JavaScript code, and find the JavaScript code that contains the line inside the web browser's appearance sourceMappingURLembeds the Ja

How do web browsers find source maps for JavaScript files?

John Sanderson The following article explains that in order to locate a JavaScript file, such as a source map of jQuery , the JavaScript code, and find the JavaScript code that contains the line inside the web browser's appearance sourceMappingURLembeds the Ja

How to ask browsers to cache files for future use

Chick I have an application that uses some large libraries. Almost 200 js and CSS files are loading. That's the way it is. First, it loads 30 of those listed in the first html. than after running. They trigger the loading of the files they need. After the libr

How to ask browsers to cache files for future use

chicken I have an application that uses some large libraries. Almost 200 js and CSS files are loading. That's the way it is. First, it loads 30 of those listed in the first html. than after running. They trigger the loading of the files they need. After the li

Browsers do not require font files

Asato I'm having a really weird problem with font-awesome. Long story short: browsers ignore the 'src' part of @font-face and make no demands on the actual font. //font-awesome.css excerpt @font-face { font-family: 'FontAwesome'; src: url('/Content/fo

Cache with PHP files

username I am creating a php script with simple coding. I don't know anything about caching. But I heard that there is object cache, database cache can shorten loading time. For example, I have a sample php query, how to enable database caching, please also te

Cache with PHP files

username I am creating a php script with simple coding. I don't know anything about caching. But I heard that there is object cache, database cache can shorten loading time. For example, I have a sample php query, how to enable database caching, please also te

Cache with PHP files

username I am creating a php script with simple coding. I don't know anything about caching. But I heard that there is object cache, database cache can shorten loading time. For example, I have a sample php query, how to enable database caching, please also te

Do web browsers cache SSL certificates?

Lorin Hochstein Do any web browsers cache SSL server certificates? For example, if I change the SSL certificate on the web server, when all web browsers connect via SSL, will all browsers choose the new certificate, or maybe they have expired certificates? I'm

Do web browsers cache SSL certificates?

Lorin Hochstein Do any web browsers cache SSL server certificates? For example, if I change the SSL certificate on the web server, when all web browsers connect via SSL, will all browsers choose the new certificate, or maybe they have expired certificates? I'm

Do web browsers cache SSL certificates?

Lorin Hochstein Do any web browsers cache SSL server certificates? For example, if I change the SSL certificate on the web server, when all web browsers connect via SSL, will all browsers choose the new certificate, or maybe they have expired certificates? I'm