使用 .php 输出 javascript 使标头过期
我已经在 PHP 中为我的所有 JS 和 CSS 文件创建了一个 minify/obfusctor/gzip 脚本,但我无法过期,但我已将其放入我的 .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>
我想要使所有类型过期 text/javascript 和 text/css 即使提取器是 PHP 文件。
我怎样才能做到这一点?
谢谢!
是的,我把 header("Content-Type: text/javascript; charset=UTF-8");
这是整个 HTTP 标头:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的解决了,我使用了 mod_expires 并删除了 PHP 文件的标头附加。
Okay resolved, i used mod_expires and i removed the Header append for PHP files.