HTML 标签中的字符大小写

发布于 2024-09-24 09:39:18 字数 937 浏览 8 评论 0原文

html标签中字符大小写的规则是什么?

我遇到一种情况,我需要在我的网站上强制不进行缓存。我一直对所有 html 标签和属性使用全部小写(给人的印象是它不区分大小写)。到目前为止,我还没有收到任何与此有关的问题。

我发现以下内容在 IE7 上有效:

<META HTTP-EQUIV="Expires" CONTENT="-1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

虽然这不起作用:

<meta http-equiv="Expires" content="-1">
<meta http-equiv="Pragma" content="no-cache">

仅供参考,我正在使用 PHP 并且还包含以下内容,但如果没有 HTML 元标记,它似乎也不起作用:

header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header("Content-Type: text/html; charset=UTF-8");

编辑(已添加):我们有以下内容文档类型(我必须承认我还不够了解这意味着什么或它的相关性)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

What's the rule for character casing in html tags?

I have a situation where I need to force no caching on a site of mine. I have been using all lower case for all html tags and attributes (being under the impression that it's case insensitive). I haven't had any issued from this, until now.

I have found that the following works on IE7:

<META HTTP-EQUIV="Expires" CONTENT="-1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

While this does not:

<meta http-equiv="Expires" content="-1">
<meta http-equiv="Pragma" content="no-cache">

FYI I am using PHP and also included the following, but it does not seem to work without the HTML meta tag as well:

header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header("Content-Type: text/html; charset=UTF-8");

EDIT (Added): We have the following doc type (I must admit I am not leet enough to know what this means or how relevant it is)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

划一舟意中人 2024-10-01 09:39:18

您是否尝试过其他版本的 IE? HTML 不区分大小写,而 XHTML 则区分大小写。以下是 W3schools 关于 HTML 的说法

HTML 提示:使用小写标签

HTML 标签不区分大小写:

含义相同。许多网站
使用大写 HTML 标签。

W3Schools 使用小写标签是因为
万维网联盟 (W3C)
建议在 HTML 4 中使用小写字母,并且
将来要求小写标签
(X)HTML 的版本。

Freedom_razor 在 codingforums 上发表的一篇文章指出 IE7 不支持就像小写元标签一样。也许您可以使用 javascript 来检测浏览器并相应地设置元标记?

Have you tried another version of IE? HTML is not case sensitive while XHTML is. Here is what W3schools says about HTML.

HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive:


means the same as

. Many web sites
use uppercase HTML tags.

W3Schools use lowercase tags because
the World Wide Web Consortium (W3C)
recommends lowercase in HTML 4, and
demands lowercase tags in future
versions of (X)HTML.

A post at codingforums by freedom_razor states that IE7 doesn't like lowercase meta tags. Maybe you could use javascript to detect the browser and set the meta tags accordingly?

后eg是否自 2024-10-01 09:39:18

嗯... META 标签实际上不应该完全没有任何效果,因为您已经发送了真正的 HTTP 标头,这应该覆盖指定为元标记的标头(HTTP-EQUIV 就是名字所说的 - 在以下情况下替换 HTTP 标头)他们不可用)。

另外...在 HTTP 标头中,您说“Expires”=“Mon, 20 Dec 1998 01:00:00 GMT”,但在元标记中您指定“Expires”=“-1”。那么您不确定您想要的 Expires 值是什么?

除此之外:缓存控制应该仅通过 HTTP 标头来实现 - 否则如何控制图像的缓存方式(图像文件中没有元标记)。

Well... the META tags shouldn't really have no effect at all, because you are already sending real HTTP headers, which should override the headers specified as meta tags (HTTP-EQUIV is what the name says - substitute for HTTP headers when they aren't available).

Also... in HTTP header you say "Expires" = "Mon, 20 Dec 1998 01:00:00 GMT", but in meta tag you specify that "Expires" = "-1". So you aren't really sure what you want the Expires value to be?

Besides that: cache control should be achieved with HTTP headers alone - how else can you control how images are cached (there are not meta-tags in image files).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文