有关CSS精灵和内存使用的快速问题 [英] Quick question regarding CSS sprites and memory usage

查看:72
本文介绍了有关CSS精灵和内存使用的快速问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,一般来说,这与图像和内存有关。如果我在页面上多次使用同一张图像,是否将每个图像合并到内存中?还是每个图像都使用单独的内存量?

Well, it's more to do with images and memory in general. If I use the same image multiple times on a page, will each image be consolidated in memory? Or will each image use a separate amount of memory?

我对此很担心,因为我正在为Windows桌面小工具构建外观系统,在默认皮肤中拼接图像,以便可以使文件系统保持干净。同时,我想尽量减少内存占用。如果我最后得到一个包含100张图像的文件,并在该小工具中重复使用该图像100次,那么我就不会遇到性能问题。

I'm concerned about this because I'm building a skinning system for a Windows Desktop Gadget, and I'm looking at spriting the images in the default skin so that I can keep the file system looking clean. At the same time I want to try and keep the memory footprint to a minimum. If I end up with a single file containing 100 images and re-use that image 100 times across the gadget I don't want to have performance issues.

干杯。 / p>

Cheers.

推荐答案

如何测试?创建一个有或没有sprit的简单应用程序,并监视Windows内存以查看哪种方法更好。

What about testing it? Create a simple application with and without spriting, and monitor your windows memory to see which approach is better.

我告诉您要测试它,因为弗拉基米尔有趣的帖子,甚至得到了 Mozilla明智地使用sprites 条目:

I'm telling you to test it because of this interesting post from Vladimir, even endorsed by Mozilla "use sprites wisely" entry:


(...)其中此图像用作精灵。请注意,这是1299x15,000 PNG。
压缩效果非常好-实际下载大小约为26,000,但浏览器
不会渲染压缩的图像数据。下载此映像并解压缩
时,它将占用几乎 75MB 的内存(1299 * 15000 * 4)。

(...) where this image is used as a sprite. Note that this is a 1299x15,000 PNG. It compresses quite well — the actual download size is around 26K - but browsers don't render compressed image data. When this image is downloaded and decompressed, it will use almost 75MB in memory (1299 * 15000 * 4).

(在弗拉基米尔(Vladimir)帖子的末尾,还有其他一些很棒的参考资料可供检查)

(At the end of Vladimir's post there are some other great references to check)

由于我不知道Windows如何渲染它的小工具(并且如果它不处理压缩的图像数据),恕我直言,恕我直言,确切地说哪种方法无需测试就更好。

Since I don't know how Windows renders it's gadgets (and if it's not going to handle compressed image data), it's dificult IMHO to say exactly which approach is better without testing.

编辑:官方 Windows桌面博客(自2007年以来未更新)说用于Windows小工具的HTML运行时是MSHTML ,所以我认为确实需要进行测试才能知道您的应用程序将如何

The official Windows Desktop blog (not updated since 2007) says the HTML runtime used for Windows Gadgets is MSHTML, so I think a test is really needed to know how your application would handle the CSS sprites.

但是,如果您阅读了一些官方的 Windows桌面小工具 Windows侧栏文档,在不使用 css sprites的事情很有趣。 (VS.85).aspx rel = nofollow noreferrer>图像协议部分:

However, if you read some of the official Windows Desktop Gadgets and Windows sidebar documentation, there's an interesting thing about your decision to not use css sprites, in the The GIMAGE Protocol section:


比标准HTML
标签将
图像添加到小工具DOM的效率更高
。此效率来自改进的缩略图处理和
图像缓存的结果
(如果
请求的大小小于256个
像素,它将尝试使用Windows缓存中的
缩略图256像素),将
与使用
file://或http://协议请求图像进行比较。 gimage协议的附加
好​​处是,可以将
而非标准图像
文件的任何文件指定为源,并且将与该文件的$ b $相关的图标指定为
会显示b类型。

This protocol is useful for adding images to the gadget DOM more efficiently than the standard HTML tag. This efficiency results from improved thumbnail handling and image caching (it will attempt to use thumbnails from the Windows cache if the requested size is smaller than 256 pixels by 256 pixels) when compared with requesting an image using the file:// or http:// protocols. An added benefit of the gimage protocol is that any file other than a standard image file can be specified as a source, and the icon associated with that file's type is displayed.

我会尝试使用此协议代替CSS Sprite并进行一些测试。

I would try to use this protocol instead of CSS sprites and do some testing too.

如果所有这些信息都无法帮助您,我将尝试在 Windows桌面小工具官方论坛

If none of this information would help you, I would try to ask at Windows Desktop Gadgets official forums.

祝你好运!

这篇关于有关CSS精灵和内存使用的快速问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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