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

查看:130
本文介绍了如何设置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;
>

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

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 标题的一些信息如下:

Some information on the Cache-Control header is as follows


HTTP 1.1。允许值= PUBLIC |私人| NO-CACHE | NO-STORE。

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

公共 - 可以缓存在公共共享缓存中。

Private - 可能只缓存在私有缓存中。

否 - 缓存 - 可能不会被缓存。

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。另见EXPIRES。

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天全站免登陆