【问题标题】:How do I set expiration headers for css.php?如何为 css.php 设置过期标头?
【发布时间】:2016-07-07 10:47:13
【问题描述】:

我使用 Zend 框架,我有很多这样的 CSS 文件

http://www.example.com/css.php?request=application%2Fthemes%2Flove%2Ftheme.css&c=2146&pageStart=15376&pageEnd=256358

如何为 css.php 设置过期标头? 事实上,我的 .htaccess 无法使用它。

我的 .htacess :

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year”
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month”
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>

谢谢

【问题讨论】:

    标签: php css performance mod-expires expires-header


    【解决方案1】:

    请在 .htaccess 中尝试以下操作

        <IfModule mod_headers.c>
      <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
      Header set Cache-Control "max-age=2678400, public"
      </filesmatch>
      <filesmatch "\.(html|htm)$">
      Header set Cache-Control "max-age=7200, private, must-revalidate"
      </filesmatch>
      <filesmatch "\.(pdf)$">
      Header set Cache-Control "max-age=86400, public"
      </filesmatch>
      <filesmatch "\.(js)$">
      Header set Cache-Control "max-age=2678400, private"
      </filesmatch>
    </IfModule>
    

    【讨论】:

    • 我使用你的 .htaccess 但没有任何改变
    • 您如何检查缓存后发生的变化? :)
    • 是的,我已经通过 Google 的 PageSpeed Insights 进行了检查 :)
    • @Rocstar 你只面临css的问题吗?
    猜你喜欢
    • 2010-12-08
    • 2012-08-14
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多