OLD | NEW |
---|---|
1 <?php | 1 <?php |
2 // Force the browser to cache this script. update() should always bypass this | 2 if(!isset($_COOKIE['mode'])) |
3 // cache and fetch a new version. | 3 $mode = 'init'; // For the first fetch, set the mode to 'init'. |
4 header('Cache-Control: max-age=86400'); | 4 else |
5 $mode = $_COOKIE['mode']; // $_COOKIE['mode'] is either 'normal' or 'error'. | |
5 | 6 |
7 // 'init' or 'normal' mode sets the normal mimetype. | |
8 if ($mode == 'init' || $mode == 'normal') { | |
9 header("Cache-Control: no-cache, must-revalidate"); | |
10 header("Pragma: no-cache"); | |
nhiroki
2015/08/10 02:32:42
Can you move these cache-control headers to out of
| |
11 header('Content-Type:application/javascript'); | |
12 if ($mode == 'init') | |
13 setcookie('mode', 'normal'); // To make 2nd fetch to work in 'normal' mode. | |
14 else | |
15 setcookie('mode', 'error'); // To make 3rd fetch to work in 'error' mode. | |
16 } | |
nhiroki
2015/08/10 02:32:42
if ($mode == 'init') {
// ...
} else if ($mode =
jungkees
2015/08/10 03:20:41
Re-organized the blocks as you commented. Looks mu
| |
17 // 'error' mode sets a disallowed mimetype. | |
18 else if ($mode == 'error') { | |
19 header("Cache-Control: no-cache, must-revalidate"); | |
20 header("Pragma: no-cache"); | |
21 header('Content-Type:text/html'); | |
22 unset($_COOKIE['mode']); | |
23 setcookie('mode', '', time() - 3600); // Delete cookie at the end of the test. | |
24 } | |
6 // Return a different script for each access. | 25 // Return a different script for each access. |
7 header('Content-Type:application/javascript'); | 26 echo '// ' . microtime(); |
8 echo '// ' . microtime() | |
9 ?> | 27 ?> |
OLD | NEW |