简体   繁体   English

处理动态站点中图像的数据URI

[英]Handling data URIs for images in a dynamic site

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. 我希望减少对移动站点的HTTP请求,作为此过程的一部分,我想利用数据URI内联发送图像。 Each page may load up to 12 thumbnails at a time, which are likely to change on refresh. 每个页面一次最多可加载12个缩略图,刷新时可能会更改。

Basically i have 2 options; 基本上我有2个选择; running base64_encode on the images on a per-request basis, or storing the encoded data in a DB and fetching that. 在每个请求的基础上对图像运行base64_encode,或将编码后的数据存储在DB中并进行提取。 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. 后者会涉及更多的工作,因为缩略图可能会定期更新,因此理想情况下,我希望使用第一种解决方案,但是前提是base64_encode的性能足以处理每页12个缩略图的编码。

I'd be appreciative of any thoughts. 我会感激任何想法。

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/ 另外,您还应该检查诸如Squid之类的缓存服务器: http : //www.squid-cache.org/

Just store in your database the file path. 只需将文件路径存储在数据库中即可。

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM