Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何指定Vary:Accept编码头?_Html_Css_.htaccess_Seo_Gzip - Fatal编程技术网

Html 如何指定Vary:Accept编码头?

Html 如何指定Vary:Accept编码头?,html,css,.htaccess,seo,gzip,Html,Css,.htaccess,Seo,Gzip,谷歌和pingdom.com说我应该 “指定一个Vary:Accept编码头” 我不知道或不明白如何做到这一点。有人能解释一下它是什么以及它的作用吗?我认为您必须为特定文件启用压缩,例如css、js和xml。 添加到域的root.htaccess文件中的以下代码将在服务器上启用此类功能: <IfModule mod_headers.c> <FilesMatch "\.(js|css|xml|gz)$"> Header append Vary: Accept-E

谷歌和pingdom.com说我应该 “指定一个Vary:Accept编码头”


我不知道或不明白如何做到这一点。有人能解释一下它是什么以及它的作用吗?

我认为您必须为特定文件启用压缩,例如
css
js
xml
。 添加到域的root.htaccess文件中的以下代码将在服务器上启用此类功能:

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

头附加变量:接受编码

如果您想向该规则添加更多文件类型,只需简单地将其扩展名添加到语句中即可<代码>

我也遇到了这个不工作的问题

发生的事情是我的php文件有另一个头指令

我有一个标题集缓存控制,它覆盖了标题,所以你必须把它们放在同一个块中。
我要做的是在一个filematch语句中为所有其他文件设置Vary,并在一个单独的filematch语句中为php文件设置Vary,如下所示:

<IfModule mod_headers.c>
<FilesMatch "\.(js|css|gz)$">
 Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>


<IfModule mod_headers.c>
<FilesMatch "\.(php)$">
 Header set Cache-Control "max-age=300"
 Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

头附加变量:接受编码
标题集缓存控制“最大年龄=300”
头附加变量:接受编码

这不是我实际的缓存控制语句-只是简化了示例代码。

我在和中获得了接近100%的分数

我发现了一篇有助于加快wordpress网站或博客速度的帖子

通过一些其他优化,我还在
.htaccess
文件(通常隐藏在主网站文件夹中)中的网站上使用以下代码

我的服务器是Apache,您可以签入主机控制面板(如cPanel/WHM面板)(如果您的服务器是nginx check keycdn.com post)

(在.htaccess文件中复制并粘贴下面的代码,这对我来说很好)

(如果对您有效,请投票选择此答案)


过期于
ExpiresByType图像/jpg“访问1个月”
过期按类型图像/jpeg“访问1个月”
ExpiresByType image/gif“访问1个月”
ExpiresByType图像/png“访问1个月”
ExpiresByType图像/svg“访问1个月”
ExpiresByType文本/css“访问1个月”
ExpiresByType text/html“访问1个月”
过期按类型应用程序/pdf“访问1个月”
ExpiresByType文本/x-javascript“访问1个月”
ExpiresByType文本/javascript“访问1个月”
ExpiresByType应用程序/javascript“访问1个月”
ExpiresByType应用程序/xhtml+xml“访问1个月”
过期按类型应用程序/x-shockwave-flash“访问1个月”
ExpiresByType图像/x图标“访问1个月”
ExpiresDefault“访问1个月”
标题集缓存控制“最大年龄=2592000,公共”
标题集缓存控制“专用,必须重新验证”
#压缩HTML、CSS、JavaScript、文本、XML和字体
AddOutputFilterByType DEFLATE应用程序/javascript
AddOutputFilterByType DEFLATE应用程序/json
AddOutputFilterByType DEFLATE应用程序/atom+xml
AddOutputFilterByType DEFLATE应用程序/rdf+xml
AddOutputFilterByType DEFLATE应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/vnd.ms-fontobject
AddOutputFilterByType放气应用程序/x-font
AddOutputFilterByType放气应用程序/x-font-opentype
AddOutputFilterByType放气应用程序/x-font-otf
AddOutputFilterByType放气应用程序/x-font-truetype
AddOutputFilterByType放气应用程序/x-font-ttf
AddOutputFilterByType放气应用程序/x-font-woff
AddOutputFilterByType DEFLATE应用程序/x-javascript
AddOutputFilterByType DEFLATE应用程序/xhtml+xml
AddOutputFilterByType DEFLATE应用程序/xml
AddOutputFilterByType泄气字体/opentype
AddOutputFilterByType DEFLATE字体/otf
AddOutputFilterByType缩小字体/truetype
AddOutputFilterByType DEFLATE字体/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType放气图像/x图标
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType泄气文本/普通
AddOutputFilterByType DEFLATE text/xml

我已将该代码添加到.htaccess文件中,但我的网站仍然没有gzip。您能提供什么帮助。。我联系了我的托管公司,他们是一群白痴,说htaccess首先不应该是网站的根!!!我不知道是什么问题。您应该将代码插入一个空文件(必须与index.html/index.php位于同一目录中)。也许它会起作用,你可以找出问题所在。尝试测试压缩。可能是浏览器缓存造成了一些问题。您的代码中有一个输入错误-您需要在“Vary”之后加上冒号:
Header append Vary:Accept Encoding
这让我从a C->B(在页眉度量上)…现在得到了关于使用cookies的消息(虽然我有一个简单的单页应用程序..gunna继续拨打..但这对我帮助很大!)要减少deflate内容,可以使用:SetOutputFilter deflate
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType image/svg "access 1 month"
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 text/javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/xhtml+xml "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>

<ifModule mod_headers.c>
  <filesMatch ".(css|jpg|jpeg|png|gif|swf|svg|js|ico)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch ".(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
  </filesMatch>
</ifModule>

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/atom+xml
  AddOutputFilterByType DEFLATE application/rdf+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-woff
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/truetype
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
</IfModule>