Performance 加速网站正确完成

Performance 加速网站正确完成,performance,apache,.htaccess,httpd.conf,Performance,Apache,.htaccess,Httpd.conf,我想加快我的网站。我想知道我的语法是否正确 <IfModule mod_expires.c> Header unset Pragma FileETag None Header unset ETag ExpiresActive On ExpiresDefault "access plus 1 year" ##### DYNAMIC PAGES <FilesMatch "\\.(ast|php)$"> ExpiresDefault A720

我想加快我的网站。我想知道我的语法是否正确

<IfModule mod_expires.c>
  Header unset Pragma
  FileETag None
  Header unset ETag
  ExpiresActive On

ExpiresDefault "access plus 1 year" 

  ##### DYNAMIC PAGES
  <FilesMatch "\\.(ast|php)$">
   ExpiresDefault A7200
    Header set Cache-Control "public, max-age=3600, must-revalidate"
  </FilesMatch>

  ##### STATIC FILES
<FilesMatch "(?i)^.*\.(ico|png|gif|jpg)$">
Header unset Last-Modified
Header set Expires "Fri, 21 Dec 2012 00:00:00 GMT"
Header set Cache-Control "public, no-transform"
</FilesMatch>

  <FilesMatch "\\.(css|js|xml)$">
    Header set Cache-Control "public, max-age=604800, must-revalidate"
</FilesMatch>

</IfModule>

标题未设置Pragma
FileTag无
标题未设置ETag
过期于
ExpiresDefault“访问权限加1年”
#####动态页面
到期默认值A7200
标题集缓存控制“公共,最大年龄=3600,必须重新验证”
#####静态文件
上次修改未设置的标题
标题集过期“2012年12月21日星期五00:00:00 GMT”
标题集缓存控制“公共,无转换”
标题集缓存控制“公共,最大年龄=604800,必须重新验证”

不要缓存asp或php或任何动态页面!这将导致不可预测的结果

下面是一个示例,假设您有一个名为catalog.php的页面,该页面显示产品目录的最新价格和库存可用性。由于您已将其设置为在浏览器上缓存结果一小时,它将在浏览器上显示过时数据一小时

动态页面不应该像这样大量缓存。您需要根据从页面返回的数据的新鲜程度,在页面上放置单独的缓存逻辑

对于静态页面,尽管您可以这样做。但是,请注意,如果您将css和js文件设置为一年后过期,那么今天访问您站点的用户在许多天或几个月内都不会从Web服务器获取最新的js和css。如果您对脚本或样式进行了更改,他们将不会看到更改,除非您使用一些独特的查询字符串手动更改文件的url

我在这里讨论了一种仅适用于ASP.NET的方法。但它告诉你该做什么和不该做什么

您还可以阅读我的7条关于充分利用缓存的提示,其中解释了所有这些方法以及每种方法的优缺点:


让我知道这是否有帮助。

我知道这个问题是从2011年开始的,但即使在那时,布拉格马还是很古老的。我认为停止使用它是安全的

我们很少需要设置“public”或必须重新验证,除非您试图支持非常旧的浏览器和代理,如IEv4之前的版本等等

如果要缓存php,还需要在php代码中做一些工作

取消对图像和内容的上次修改实际上会导致在静态(当时)未来日期的预定日期之前,这些文件的“从不缓存”情况。我认为您希望在未来X天内始终缓存静态文件,而不是上次修改时取消设置

您的htaccess文件可以变得更简单。我们可以将其现代化一点,使其成为:

## set some mime types to their proper types
AddType application/javascript      js jsonp
AddType application/json            json
AddType application/xml             rss atom xml rdf
AddType image/x-icon                ico


<IfModule mod_deflate.c>
  # Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  # Compress all output labeled with one of the following MIME-types
  # (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
  # and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines as
  # `AddOutputFilterByType` is still in the core directives)
  <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
                                  application/javascript \
                                  application/json \
                                  application/rss+xml \
                                  application/vnd.ms-fontobject \
                                  application/x-font-ttf \
                                  application/xhtml+xml \
                                  application/xml \
                                  font/opentype \
                                  image/svg+xml \
                                  image/x-icon \
                                  text/css \
                                  text/html \
                                  text/plain \
                                  text/x-component \
                                  text/xml
  </IfModule>
</IfModule>


<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresDefault                          "access plus 1 month"
# Your document html
  ExpiresByType text/html                 "access plus 0 seconds"
# Data
  ExpiresByType application/json          "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType text/xml                  "access plus 0 seconds"
# Feed
  ExpiresByType application/atom+xml      "access plus 1 hour"
  ExpiresByType application/rss+xml       "access plus 1 hour"
# Favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 week"
# images
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
# CSS and JavaScript
  ExpiresByType application/javascript    "access plus 1 year"
  ExpiresByType text/css                  "access plus 1 year"
</IfModule>

# ----------------------------------------------------------------------
# Prevent mobile network providers from modifying your site
# ----------------------------------------------------------------------

# The following header prevents modification of your code over 3G on some
# European providers.
# This is the official 'bypass' suggested by O2 in the UK.

<IfModule mod_headers.c>
Header set Cache-Control "no-transform"
</IfModule>


# ----------------------------------------------------------------------
# ETag removal
# ----------------------------------------------------------------------

# FileETag None is not enough for every server.
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>

# Since we're sending far-future expires, we don't need ETags for
# static content.
#   developer.yahoo.com/performance/rules.html#etags
FileETag None
##将某些mime类型设置为正确的类型
AddType应用程序/javascript jsonp
AddType应用程序/json
AddType应用程序/xml rss原子xml rdf
AddType图像/x图标图标图标
#针对破损的标题强制放气developer.yahoo.com/blogs/ydn/posts/2010/12/push-beyond-gzip/
SetEnvIfNoCase^((gzip | deflate)\s*,?\s*)+|[X~-]{4,13}$有接受编码
RequestHeader追加接受编码“gzip,deflate”env=HAVE_Accept-Encoding
#压缩使用以下MIME类型之一标记的所有输出
#(对于低于2.3.7的Apache版本,您不需要启用'mod_filter'`
#并且可以删除``和``行,如下所示:
#`AddOutputFilterByType`仍在核心指令中)
AddOutputFilterByType DEFLATE应用程序/atom+xml\
应用程序/javascript\
应用程序/json\
application/rss+xml\
应用程序/vnd.ms-fontobject\
应用程序/x-font-ttf\
application/xhtml+xml\
应用程序/xml\
字体/开放式\
image/svg+xml\
图像/x图标\
文本/css\
文本/html\
文本/纯文本\
文本/x组件\
文本/xml
过期于
ExpiresDefault“访问加1个月”
#您的文档是html
ExpiresByType text/html“访问加0秒”
#资料
ExpiresByType应用程序/json“访问加0秒”
ExpiresByType应用程序/xml“访问加0秒”
ExpiresByType text/xml“访问加0秒”
#喂
ExpiresByType应用程序/atom+xml“访问加1小时”
ExpiresByType应用程序/rss+xml“访问加1小时”
#Favicon(无法重命名)
ExpiresByType图像/x图标“访问加1周”
#图像
ExpiresByType image/gif“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType图像/png“访问加1个月”
#CSS和JavaScript
ExpiresByType应用程序/javascript“访问加1年”
ExpiresByType文本/css“访问加1年”
# ----------------------------------------------------------------------
#阻止移动网络提供商修改您的站点
# ----------------------------------------------------------------------
#以下标题防止在某些情况下通过3G修改代码
#欧洲供应商。
#这是O2在英国提出的官方“旁路”。
标头集缓存控制“无转换”
# ----------------------------------------------------------------------
#ETag去除
# ----------------------------------------------------------------------
#FileTag None对于每台服务器都是不够的。
标题未设置ETag
#因为我们发送的是远期到期,所以我们不需要ETag
#静态内容。
#developer.yahoo.com/performance/rules.html#etags
FileTag无

谷歌有一个网站