cache_javascript_headers()
Sets headers for the Javascript file and caches it for 10 days.
The function is convenient for creating a dynamic Javascript file in PHP. It can be called to set the necessary headers for such a file (see the function code).
No Hooks.
Returns
null. Returns nothing.
Usage
cache_javascript_headers();
Examples
#1 The function sets the following headings:
header( "Content-Type: text/javascript; charset=UTF-8" ); header( "Vary: Accept-Encoding" ); header( "Expires: Wed, 27 Mar 2013 02:47:29 GMT" );
Changelog
| Since 2.1.0 | Introduced. |
cache_javascript_headers() cache javascript headers code WP 6.9.1
function cache_javascript_headers() {
$expires_offset = 10 * DAY_IN_SECONDS;
header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) );
header( 'Vary: Accept-Encoding' ); // Handle proxies.
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
}