HTML 标签中的字符大小写
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过其他版本的 IE? HTML 不区分大小写,而 XHTML 则区分大小写。以下是 W3schools 关于 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.
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?
嗯... 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).