【问题标题】:Difference between meta cache tag and htaccess caching?元缓存标记和 htaccess 缓存之间的区别?
【发布时间】:2015-01-17 22:47:40
【问题描述】:

我目前在我的 .htaccess 文件中有这个用于资源缓存:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 1 month"
</IfModule>

我是否还需要在我的页面上添加Cache-Control 元标记才能应用这些规则?即

&lt;meta http-equiv="Cache-control" content="public"&gt;

【问题讨论】:

    标签: css html .htaccess caching


    【解决方案1】:

    两者都设置了不同的标题和值,无论您使用哪种方法,浏览器中的结果都将相同。主要区别在于每个文件可以应用于的文件类型:

    *a <meta> tag can only appear inside an HTML document; consequently, you cannot use it to control cache validity on non-HTML files (such as images), and it's possible that something would download the file without processing the HTML and spotting the tag.*
    
    *the Apache Header directive (not part of mod_rewrite) can be applied to any file that Apache is serving, whether it is dynamically generated or not. This can include images, static HTML, CSS, and JS, plus whatever content you generate with PHP.*
    

    Apache 指令的唯一缺点是,根据您对 Apache 配置规则的设置和经验,可能难以为不同的数据位维护更复杂的规则。

    您可能想尝试使用 PHP,如下所示:

    the PHP header() function can affect any file that you are serving dynamically with PHP. This could include, for instance, plain text or XML files, but might not include an HTML file you'd uploaded fully formed to your server. You could pass static files, including images, through PHP, but this would be an inefficient way of serving them.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-24
      • 2022-11-17
      • 2011-03-12
      • 2015-07-17
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多