I am using php for generating javascript dynamically based on different conditions. I want browser to be able to cache it for specific amount of time.
I am using the following code for caching, but it doesn’t seem to be working.
header("Content-type: text/javascript; charset: UTF-8");
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($ExpStr);
Also, The js file is quite big, ~290 KBs, So I want to send it compressed to the browser to reduce download time. any suggestions?
You forgot the Expires header name, So the line
Should be
And for compressing the output, uncomment ( or add if not exists) the following line in PHP.ini. to deflate or compress the output. Don’t forget to restart the server after modifying PHP.ini