3

There is a lot of advice how to use headers to prevent the browser from caching a file. I wish to do the opposite. The cache.php file below never changes. I've tested this using FF, Chrome, and FF, and each time index.html is reloaded, the cache.php is downloaded from the server. How do I tell the browser to cache the JavaScript file "cache.php"? Thank you

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 
        <title>Testing</title>  
        <script src="cache.php" type="text/javascript"></script> 
    </head>
    <body>
        <p>Hello!</p>
    </body> 
</html> 

cache.php

<?php
    syslog(LOG_INFO,'cache.php'.rand());
    header( 'Content-type: text/javascript' );
    echo('alert("Hello!");');    
?> 
4

1 回答 1

0

您必须在 PHP 中实现缓存处理。检查此问题及其答案以获取详细信息:如何使用 HTTP 缓存标头与 PHP

于 2013-06-01T17:05:59.330 回答