【问题标题】:How to prevent the server caching css?如何防止服务器缓存css?
【发布时间】:2015-11-07 03:49:36
【问题描述】:

如何防止服务器使用 .htaccess 缓存 css?我已经尝试了以下

# enable expirations
ExpiresActive On
# expire GIF images after a month in the client's cache
ExpiresByType style/css 1

freenode 用户推荐 (#httpd)。

但是这使我的服务器 500。 他们做错了什么?

【问题讨论】:

    标签: css apache .htaccess caching


    【解决方案1】:

    我不知道为什么你的服务器会变成 500,但这就是我的 .htaccess 文件的样子,而且它对我来说运行良好。基于this .htaccess file(从第 668 行开始的部分)。

    <IfModule mod_expires.c>
        ExpiresActive on
        ExpiresDefault                                      "access plus 1 month"
    
        ExpiresByType text/css                              "access plus 0 seconds"
    
        ...
    
    </IfModule>
    

    如果/当网站投入生产时,您可能会想要更改此设置。

    另外,我已经养成了对我的 css 文件进行版本控制的习惯,例如:

    <link rel="stylesheet" type="text/css" href="http://path/style.css?v=0.03" />
    

    更改“版本号”将强制重新加载。如果您愿意,可以使用 PHP 自动执行此版本控制过程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2011-04-02
      相关资源
      最近更新 更多