Search code examples
phpapache.htaccessmod-expires

Expires Header with a .php output javascript


I have creating a minify/obfusctor/gzip script in PHP of all my JS and CSS files but I can't expire but I have put this in my .htaccess:

ExpiresActive On
ExpiresDefault A0
ExpiresByType text/css "access plus 2 hours"
ExpiresByType text/javascript "access plus 2 hours"
ExpiresByType application/x-javascript "access plus 2 hours"
Header append Cache-Control "proxy-revalidate"

<FilesMatch "\.(xml|txt|html|js|css)$">
    ExpiresDefault A7200
    Header append Cache-Control "proxy-revalidate"
</FilesMatch>

<FilesMatch "\.(php|cgi|pl|htm)$">
    ExpiresActive Off
    Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    Header set Pragma "no-cache"
</FilesMatch>

I want to expire all types text/javascript and text/css even if the extractor is a PHP file.

How can I do that?

Thx!


yes i put header("Content-Type: text/javascript; charset=UTF-8");

Here is the entire HTTP Header :

Date: Sat, 20 Nov 2010 19:02:05 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By: PHP/5.3.0
Content-Encoding: gzip
Last-Modified: Sat, 20 Nov 2010 16:03:24 GMT
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 181781
Pragma: no-cache
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/javascript; charset=UTF-8

200 OK

Solution

  • Okay resolved, i used mod_expires and i removed the Header append for PHP files.

    ExpiresActive On
    ExpiresDefault A1
    ExpiresByType text/javascript A7200
    ExpiresByType application/x-javascript A7200
    
    <FilesMatch "\.(js)$">
    Header append Cache-Control "max-age=7200, private"
    </FilesMatch>