添加过期标题 [英] Add Expires headers

查看:135
本文介绍了添加过期标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Add Expires headers
There are 21 static components without a far-future expiration date.

    http://static.doers.lk/examples-offline.css
    http://static.doers.lk/kendo.common.min.css
    http://static.doers.lk/kendo.default.min.css
    http://static.doers.lk/style.css
    http://static.doers.lk/jquery.min.js
    http://static.doers.lk/kendo.web.min.js
    http://static.doers.lk/console.js
    http://static.doers.lk/sprite.png
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    https://fbexternal-a.akamaihd.net/safe_image.php?...
    http://static.doers.lk/favicon.PNG

当我测试网站使用雅虎YSLOW它说上述massage.So我不知道如何添加过期headers.any帮助将不胜感激?

When i testing the site using yahoo YSLOW it says above massage.So i don't know how to add expire headers.any help would be appreciated ?

推荐答案

添加这些头文件的最简单方法是在code> .htaccess 文件中添加一些配置到您的服务器。如果这些资产托管在您无法控制的服务器上,那么您就无能为力。

The easiest way to add these headers is a .htaccess file that adds some configuration to your server. If the assets are hosted on a server that you don't control, there's nothing you can do about it.

请注意,某些托管提供商不允许您使用 .htaccess 文件,所以检查他们的条款,如果它似乎不工作。

Note that some hosting providers will not let you use .htaccess files, so check their terms if it doesn't seem to work.

HTML5Boilerplate项目有一个很好的 .htaccess 涵盖必要设置的文件。在他们的 Github存储库中查看文件的相关部分

The HTML5Boilerplate project has an excellent .htaccess file that covers the necessary settings. See the relevant part of the file at their Github repository

这些都是重要的一点

These are the important bits

# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------

# These are pretty far-future expires headers.
# They assume you control versioning with filename-based cache busting
# Additionally, consider that outdated proxies may miscache
# www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

# If you don't use filenames to version, lower the CSS and JS to something like
# "access plus 1 week".

<IfModule mod_expires.c>
  ExpiresActive on

# Your document html
  ExpiresByType text/html "access plus 0 seconds"

# Media: images, video, audio
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"

# CSS and JavaScript
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/css "access plus 1 year"
</IfModule>

他们有记录了这个文件的功能,最重要的是你需要重新命名你的CSS和Javascript文件,因为你的访问者浏览器在缓存后不会再检查一年。

They have documented what that file does, the most important bit is that you need to rename your CSS and Javascript files whenever they change, because your visitor's browsers will not check them again for a year, once they are cached.

这篇关于添加过期标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆