如何设置 HTTP 标头(用于缓存控制)? [英] How to set HTTP headers (for cache-control)?

查看:39
本文介绍了如何设置 HTTP 标头(用于缓存控制)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为我的网站启用浏览器缓存?我是不是像这样将 cache-control:public 放在标题中的某个位置?

How to enable browser caching for my site? Do I just put cache-control:public somewhere up in my header like this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
Cache-Control:public;
>

我正在使用最新版本的 PHP 在最新版本的 XAMPP 上开发.

I am using the latest version of PHP developing on the latest version of XAMPP.

推荐答案

要在 HTML 中使用缓存控制,您可以使用 元标记,例如

To use cache-control in HTML, you use the meta tag, e.g.

<meta http-equiv="Cache-control" content="public">

内容字段中的值定义为以下四个值之一.

The value in the content field is defined as one of the four values below.

Cache-Control 头部的一些信息如下

HTTP 1.1.允许值 = PUBLIC |私人 |无缓存 |没有商店.

HTTP 1.1. Allowed values = PUBLIC | PRIVATE | NO-CACHE | NO-STORE.

公共 - 可以缓存在公共共享缓存中.
私有 - 只能缓存在私有缓存中.
无缓存 - 可能不会被缓存.
No-Store - 可以缓存但不能存档.

Public - may be cached in public shared caches.
Private - may only be cached in private cache.
No-Cache - may not be cached.
No-Store - may be cached but not archived.

指令 CACHE-CONTROL:NO-CACHE 表示不应使用缓存信息而是将请求转发到源服务器.该指令与 PRAGMA:NO-CACHE 具有相同的语义.

The directive CACHE-CONTROL:NO-CACHE indicates cached information should not be used and instead requests should be forwarded to the origin server. This directive has the same semantics as the PRAGMA:NO-CACHE.

客户端应该同时包含 PRAGMA: NO-CACHE 和 CACHE-CONTROL: NO-CACHE,当无缓存请求发送到未知的 HTTP/1.1 兼容服务器时.另请参阅过期.

Clients SHOULD include both PRAGMA: NO-CACHE and CACHE-CONTROL: NO-CACHE when a no-cache request is sent to a server not known to be HTTP/1.1 compliant. Also see EXPIRES.

注意:在 HTTP 中指定缓存命令可能比在 META 语句中指定缓存命令更好,在 META 语句中,它们可以影响的不仅仅是浏览器,还有代理和其他可能缓存信息的中介.

Note: It may be better to specify cache commands in HTTP than in META statements, where they can influence more than the browser, but proxies and other intermediaries that may cache information.

这篇关于如何设置 HTTP 标头(用于缓存控制)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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