用于 Web 开发的 Sprite 表
我目前正在开发一个新网站。我只了解了几页,它们都使用 s
。我正在考虑这个问题,并决定考虑对所有按钮图像等使用精灵表,然后只使用 CSS 来渲染适当的图像。我想看看大家对此有何看法。值得付出努力吗?它如何影响 SEO,特别是 s
的 ALT。还有什么我应该注意的吗?
提前致谢!
I'm currently working on a new site. I'm just a few pages deep and they all use <img>s
. I was thinking about it and decided to look into using a sprite sheet for all of the button images and such and then just using CSS to render the appropriate images. I wanted to see what everyone thought about this. Is it worth the effort? How does it affect SEO, specifically ALTs for <img>s
. Is there anything else that I should be aware of?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,作为内容一部分的图像应该使用图像标签,其他所有内容都可以使用背景图像/CSS 精灵。
通过包含带有 alt 属性的普通图像标签,您将使图像可用于 google 图片搜索等。但是,这不是我非常重视的因素。
重要的是,如果有人使用屏幕阅读器查看您的网站或只是查看 HTML,则可以通过图像标签和 alt 属性成功传达内容。如果您将 div 与 CSS 一起使用,您将失去这种效果,并且有些人可能会错过内容。
但是,当涉及非重复背景图像、按钮和其他面向样式的图像时,我确实建议使用 CSS Sprites 来提高性能。
虽然将其他图像放入真实图像标签中的效果应该会稍差一些,但如果您在图像上正确设置缓存标头,则效果可能会非常小。
编辑:
快速搜索发现了这个:
http://www.google.com/support /forum/p/Webmasters/thread?tid=75fa18ce5e671f5b&hl=en
这似乎通过将文本放置在 div 中然后使用精灵隐藏文本来减轻 Alt 属性的影响:
Google 使用的方法,链接内的相关文本,对爬虫、关闭图像的人、屏幕阅读器等可见。
如果性能可能是一个问题,那么可能值得走这条路,但我确实更喜欢更具语义的 img 标签,如果它们是内容的一部分。
In my opinion, images which are part of content should use image tags, and everything else can use background images/CSS sprites.
By including a normal image tag with an alt attribute, you will make the image available for things like google image search. But, this is not a factor I weigh very heavily.
The important part is that if someone looks at your site with a screen reader or simply views the HTML, the content will be successfully conveyed with an image tag and alt attribute. If you use divs with CSS you will lose this effect, and some people might miss the content.
But, when it comes to non repeating background images, buttons, and other style oriented images, I do recommend using CSS Sprites to improve performance.
While putting the other images in real image tags should preform slightly worse, this can be very minimal if you set the caching headers properly on the images.
Edit:
A quick search found this:
http://www.google.com/support/forum/p/Webmasters/thread?tid=75fa18ce5e671f5b&hl=en
Which seems to mitigate the Alt attribute by placing text in the div and then using sprites to hide the text:
The approach Google uses, relevant text inside link, visible for crawlers, people who have images turned off, screen readers, etc.
If performance is likely to be an issue it might be worth going that route but I do prefer the more semantic img tags if they are part of the content.
精灵绝对值得付出努力。它们节省了加载时间,提高了响应速度,并且还利用了缓存,所有这些结合起来可以显着减少加载时间。
Alt 仍然可以照常应用。
SEO方面,不应该有负面影响。您没有应用任何会阻止爬虫的奇异方法(阅读:flash),一切都维护 W3 标准,所以一切都应该没问题。请务必通过 W3 验证器运行它,以确保其他一切都是正确的。
如果谷歌这么做了,那一定会很好,对吧?
Sprites are definitely worth the effort. They save load time, increase response, and also take advantage of caching, which can all combine to dramatically decrease load time.
Alts can still be applied as usual.
SEO wise, there should be no negative effects. You're not applying any exotic methods (read: flash) that will block the crawlers, everything maintains W3 standards, so all should be fine. Be sure to run it through the W3 validator to ensure everything else is kosher.
If Google's doing it, it's gotta be good, right?