Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteNo. A PHP page cannot set expiration headers on a JavaScript file fetched directly from another host. PHP’s header() function sends headers with the PHP response; the server or service returning the external script controls that script’s separate response. To change its cache policy, the provider must do so, or you must serve the script through infrastructure you control.
Why PHP cannot set cache headers for a directly linked script
When a browser loads a PHP page, it receives one HTTP response for that page. If the page references a script hosted elsewhere, the browser makes a separate request to that script’s URL and receives a separate response. Headers emitted by PHP apply to the PHP response; they do not rewrite headers on the third-party server’s response. The PHP Manual describes header() as a way to send a raw HTTP header and notes it must be called before output: PHP Manual: header().
So adding header('Expires: ...') to the embedding page will not extend the cache lifetime of a script the browser fetches directly from an external domain. It may affect caching of the PHP page itself, which is a different resource.
Choose a route based on who controls the script response
| Option | Who controls response headers? | Main trade-off |
|---|---|---|
| Keep the direct third-party URL | The third-party response path | Lowest operational work, but PHP on your page cannot set that response’s headers. |
| Ask the provider or use its supported settings | The provider | Keeps provider-hosted delivery; availability of cache settings depends on the provider. |
| Serve an authorized local copy | Your web server | Gives you control over the response, but you are responsible for keeping the copy current. |
| Proxy the request through controlled infrastructure | Your proxy and server configuration, subject to upstream behavior | Can put the delivery path under your control, but adds maintenance and may retain stale content. |
Before mirroring or proxying a third-party script, confirm that the provider permits it and consider security, update frequency, and what would happen if your copy became outdated. A proxy is an architectural change, not a PHP header fix.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
If PHP itself serves the script
If the requested resource is a PHP-generated response, that PHP script can set its own cache policy before it sends any body output. For example:
<?php
header('Cache-Control: public, max-age=3600');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
?>
This example sets a one-hour freshness period for the response served by that PHP script; it is not a recommendation for every asset. Choose a lifetime based on how often the resource changes and whether clients can safely use a previously cached version. For frequently updated scripts, a shorter lifetime or a versioned URL may be more appropriate; for stable, versioned assets, a longer lifetime may be reasonable.
Rank #2
The PHP Manual’s caching example uses Cache-Control: no-cache, must-revalidate and an already-expired Expires value to discourage reuse. That is an anti-caching example, not a long-lived asset policy. Do not copy it when the goal is browser reuse. PHP Manual: header()
If Apache serves or proxies the asset
Apache HTTP Server 2.4’s mod_expires can generate expiration and cache-control headers for responses served through Apache. Its directives include ExpiresActive, ExpiresByType, and ExpiresDefault. For example, where the module is enabled and the configuration context permits it, a site might set a default expiration for JavaScript responses:
ExpiresActive On
ExpiresByType application/javascript "access plus 1 hour"
Apache allows configuration in server, virtual-host, directory, or .htaccess contexts where permitted. Check that mod_expires is enabled and that the host allows the chosen context. Expiry can be based on access time or file modification time. See the Apache mod_expires documentation for supported syntax and configuration details.
Do not assume this overrides all upstream cache policies. Apache documents that if an Expires header is already present—including one from CGI or a proxied origin—mod_expires does not add or change the Expires or Cache-Control headers.
Rank #4
If Nginx serves or proxies the asset
Nginx’s ngx_http_headers_module provides the expires directive, which sets or modifies Expires and Cache-Control on eligible responses. For example, within an appropriate location serving JavaScript:
location ~* .js$ {
expires 1h;
}
A positive duration produces a Cache-Control: max-age=... value; a negative duration produces no-cache. The separate add_header directive is limited by documented response-status and inheritance rules, so placement in the configuration matters. Review the Nginx ngx_http_headers_module documentation before using it, especially when configuration is nested or the response comes from an upstream server.
Check the response that the browser actually receives
- Open the exact script URL in your browser’s developer tools or an HTTP client and inspect its response headers and status.
- Confirm whether the URL belongs to your site, a proxy you control, or a third-party provider. The response origin determines who can set the policy.
- After changing server configuration, check the same URL again. Verify the resulting
Cache-ControlandExpiresvalues rather than assuming the configuration took effect.
Expires is not the only caching control: HTTP caching also uses Cache-Control directives. The applicable semantics are defined in RFC 9111, HTTP Caching.
Session cache settings do not solve this problem
PHP’s session_cache_limiter() controls cache-related headers for the response in which PHP starts a session. Its modes include public, private, private_no_expire, and nocache; none gives the PHP page authority over a script response from another host. See the PHP Manual: session_cache_limiter().
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

