使用 .php 输出 javascript 使标头过期

发布于 2024-10-03 16:59:16 字数 1348 浏览 8 评论 0原文

我已经在 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/javascripttext/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心小果奶 2024-10-10 16:59:16

好的解决了,我使用了 mod_expires 并删除了 PHP 文件的标头附加。

ExpiresActive On
ExpiresDefault A1
ExpiresByType text/javascript A7200
ExpiresByType application/x-javascript A7200

<FilesMatch "\.(js)$">
Header append Cache-Control "max-age=7200, private"
</FilesMatch>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文