数据 uri:s 的 MSHTML 后备

发布于 2024-12-05 14:15:05 字数 544 浏览 4 评论 0原文

我的网站使用数据 uri:s 来减少对我网站的 HTTP 请求数量。问题是 data uri:s 在我们必须支持的浏览器 IE7 中不起作用(不,我们不需要 IE6)。我已经按照 Stoyan 的指南 进行操作,并且实际上让它工作了,但是经过一段时间后最近的 Microsoft 安全更新(KB2544893,如 对原始文章的评论)后备似乎已停止工作。

上面引用的评论建议我应该尝试发送带有 Content-Type message/rfc822 的 MSHTML 文件,但我也无法让它工作,并且我在几个小时的过程中尝试了多种不同的方法。

所以我的问题是这样的:你能让 Stoyan 描述的技术以某种方式发挥作用吗?我真的很感激一个有效的例子来让我相信这确实是可能的。

My site uses data uri:s to reduce the number of HTTP requests to my site. The problem is that data uri:s don't work in IE7, a browser that we have to support (No, we don't need IE6). I've followed Stoyan's guide and actually gotten it to work, but after a recent Microsoft security update (KB2544893, as descibed in a comment on the original article) the fallback seems to have stopped working.

The comment referenced above suggests I should try sending the MSHTML file with Content-Type message/rfc822, but I can't get this to work either, and I've tried multiple different ways over a course of several hours.

So my question is this: Can you get the technique described by Stoyan to work somehow? I would really appreciate a working example to convince me that it truly is possible.

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

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

发布评论

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

评论(3

盛夏尉蓝 2024-12-12 14:15:05

我个人会使用条件样式。在您的主要标记中 - 按如下方式启动:

<!DOCTYPE html>
<!--[if IE 7]>    <html lang="en-us" class="ie7"> <![endif]-->
<!--[if IE 8]>    <html lang="en-us" class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us"> <!--<![endif]-->

在您的 css 中,您现在可以执行以下操作:

.myClass {
      background-image: url(/*DATAURI GOES HERE*/);
}

.ie7 .myClass {
      background-image: url(fallback-image.png);
}

更新

除了下面的评论之外,如果您担心 IE7 性能 - 一个可靠的方法是使您的IE7 后备图像精灵

这样您只需为 IE7 用户进行 1 次额外的 HTTP 调用:

.ie7 .myClass {
      background-image: url(fallback-sprite.png);
      background-position: 150px 15px;
}

Personally I would use conditional styles. In your main markup - start it as follows:

<!DOCTYPE html>
<!--[if IE 7]>    <html lang="en-us" class="ie7"> <![endif]-->
<!--[if IE 8]>    <html lang="en-us" class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us"> <!--<![endif]-->

In your css you can now do:

.myClass {
      background-image: url(/*DATAURI GOES HERE*/);
}

and

.ie7 .myClass {
      background-image: url(fallback-image.png);
}

UPDATE

Further to the comments below, if you're concerned around IE7 performance - a reliable approach would be to make your IE7 fallback image a sprite.

That way you're only making 1 additional HTTP call for IE7 users:

.ie7 .myClass {
      background-image: url(fallback-sprite.png);
      background-position: 150px 15px;
}
葬﹪忆之殇 2024-12-12 14:15:05

我联系了 Stoyan Stefanov(该技术的原作者),他修复了原来的示例,使其现在可以正常工作。只需添加“message/rfc822”作为内容类型即可。

固定示例: http://www.phpied.com/files/datasprites/testhover2.html< /a>

我让他在这里发表评论,这样我就可以奖励积分,但他不愿意。

I got in contact with Stoyan Stefanov (the original author of the technique), and he fixed his original example so it now works. Simply adding "message/rfc822" as content-type was all that's needed.

Fixed example: http://www.phpied.com/files/datasprites/testhover2.html

I asked him to post a comment here so I could award the points, but he didn't want to.

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