处理动态站点中图像的数据 URI
我希望减少移动网站的 HTTP 请求,并且作为其中的一部分,我希望利用数据 URI 来内联发送图像。每个页面一次最多可以加载 12 个缩略图,这些缩略图可能会在刷新时发生变化。
基本上我有两个选择;根据每个请求对图像运行 base64_encode,或者将编码数据存储在数据库中并获取该数据。后者会涉及更多的工作,因为缩略图可能会定期更新,所以理想情况下我想要第一个解决方案,但前提是 base64_encode 的性能能够处理每页 12 个缩略图的编码。
我将不胜感激任何想法。
I'm looking to cut down on HTTP requests for a mobile site and, as part of this, would like to utilise data URIs for sending images inline. Each page may load up to 12 thumbnails at a time, which are likely to change on refresh.
Basically i have 2 options; running base64_encode on the images on a per-request basis, or storing the encoded data in a DB and fetching that. The latter would involve a bit more work as the thumbnails may be updated periodically, so ideally I'd like the first solution, but only if the performance of base64_encode is such that it can handle encoding 12 thumbnails per page.
I'd be appreciative of any thoughts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将图像作为纯图像文件提供,但来自单独的域。由于文件如何提供给客户端,使用图像或媒体域可能更合适。
另外你应该检查像 Squid 这样的缓存服务器: http://www.squid-cache.org/
只是将文件路径存储在数据库中。
希望它能帮助你。
You should serve your image as plain image file, but from a separate domain. Because of how files are serve to the client, using a domain for images or medias could be more appropriate.
Also you should check caching server like Squid : http://www.squid-cache.org/
Just store in your database the file path.
Hope it will help you.