Home > Backend Development > PHP Tutorial > Problem with header('Cache-Control:no-cache')

Problem with header('Cache-Control:no-cache')

WBOY
Release: 2016-09-09 08:28:03
Original
2150 people have browsed it

Good afternoon everyone, I read in the book that header("Cache-Control:no-cache") can force the browser not to use cache, so I wanted to test the effect. The code is as follows:

<code><?php
header("Pragma:no-cache");  
header("Cache-Control:no-cache,must-revalidate");  
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <img src="1.jpg" alt="">
</body>
</html>
</code>
Copy after login
Copy after login

But I didn’t see the expected effect. Every time I refreshed the page, 304 was returned. Why not 200?

Problem with header('Cache-Control:no-cache')

It’s really hard to guess. . .

Reply content:

Good afternoon everyone, I read in the book that header("Cache-Control:no-cache") can force the browser not to use cache, so I wanted to test the effect. The code is as follows:

<code><?php
header("Pragma:no-cache");  
header("Cache-Control:no-cache,must-revalidate");  
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <img src="1.jpg" alt="">
</body>
</html>
</code>
Copy after login
Copy after login

But I didn’t see the expected effect. Every time I refreshed the page, 304 was returned. Why not 200?

Problem with header('Cache-Control:no-cache')

It’s really hard to guess. . .

html isn’t it 200 anymore? .
jpg is a static file, it is returned in apache/nginx without using php at all, and the cache is also handled by the server.

Clear browser cache.
The first time it is loaded, 200 is returned. If there are no changes on the server side, 304 will be returned.
If you want to force refresh the page, press Ctrl+F5 on Google Chrome.
Check if your web server (such as nginx) has cache enabled.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template